how can i convert the number into hexadecimal, binary and decimal using assembly language program?

Update:

Example my input is 90 what will be the result of this number into the hexadecimal, binary and decimal using assembly language program.. tnx for helping me

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    /*the following C program convetrs the given decimal number to binary ,octal & hexadecimal for any positive decimal number *\

    #include<stdio.h>

    void main()

    {

    int a[32],n,c,i,m,k,v;

    printf("enter ur number");

    scanf("%d",&n);

    for(i=0;i<3;i++)

    {

    if (i==0) c=2,printf("in binary:\n");

    if(i==1) c=8;printf("in octal:\n");

    if(i==2) c=16;printf("in hexadecimal:\n");

    m=n,k=0;

    do

    {

    v=m%c;

    a[k]=v;

    k=k+1;

    m=m/10;

    }while(m!=0)

    for(i=(k-1);i>=0;i- -)

    {

    if(a[i]==10)printf("A");

    if(a[i]==11)printf("B");

    if(a[i]==12)printf("C");

    if(a[i]==13)printf("D");

    if(a[i]==14)printf("E");

    if(a[i]==15)printf("F");

    else if(a[i]<10)printf("%d",a[i]);

    }

    printf("\n");

    }

    }

    -------------------------------------------------------------------------------------------------------

    i dont understant the question of converting the number to decimal when ur input is in decimal...for quiries on above program mail me...i tried this on turbo c compiler and it worked.

    all the best

    note:

    /*using same variable in two for loops does not cause error,u may use other variable*/

    • Commenter avatarLogin to reply the answers
  • 1 decade ago

    Although we can convert between decimal and binary, the conversion is not a trivial task. The hexadecimal (base 16) numbering system solves these problems. Hexadecimal numbers offer the two features we're looking for: they're very compact, and it's simple to convert them to binary and vice versa. Because of this, most binary computer systems today use the hexadecimal numbering system.

    Since the radix (base) of a hexadecimal number is 16, each hexadecimal digit to the left of the hexadecimal point represents some value times a successive power of 16. For example, the number 1234 (hexadecimal) is equal to:

    1 * 16**3 + 2 * 16**2 + 3 * 16**1 + 4 * 16**0

    or

    4096 + 512 + 48 + 4 = 4660 (decimal).

    Each hexadecimal digit can represent one of sixteen values between 0 and 15. Since there are only ten decimal digits, we need to invent six additional digits to represent the values in the range 10 through 15. Rather than create new symbols for these digits, we'll use the letters A through F. The following are all examples of valid hexadecimal numbers:

    1234 DEAD BEEF 0AFB FEED DEAF

    Since we'll often need to enter hexadecimal numbers into the computer system, we'll need a different mechanism for representing hexadecimal numbers. After all, on most computer systems you cannot enter a subscript to denote the radix of the associated value. We'll adopt the following conventions:

    All numeric values (regardless of their radix) begin with a decimal digit.

    All hexadecimal values end with the letter "h", e.g., 123A4h.

    All binary values end with the letter "b".

    Decimal numbers may have a "t" or "d" suffix.

    Examples of valid hexadecimal numbers:

    1234h 0DEADh 0BEEFh 0AFBh 0FEEDh 0DEAFh

    As you can see, hexadecimal numbers are compact and easy to read. In addition, you can easily convert between hexadecimal and binary. Consider the following table:

    Binary=Hexadecimal

    0000 = 0

    0001 = 1

    0010 = 2

    0011 = 3

    0100 = 4

    0101 = 5

    0110 = 6

    0111 = 7

    1000 = 8

    1001 = 9

    1010 = A

    1011 = B

    1100 = C

    1101 = D

    1110 = E

    1111 = F

    This table provides all the information you'll ever need to convert any hexadecimal number into a binary number or vice versa.

    To convert a hexadecimal number into a binary number, simply substitute the corresponding four bits for each hexadecimal digit in the number. For example, to convert 0ABCDh into a binary value, simply convert each hexadecimal digit according to the table above:

    0 A B C D Hexadecimal

    0000 1010 1011 1100 1101 Binary

    To convert a binary number into hexadecimal format is almost as easy. The first step is to pad the binary number with zeros to make sure that there is a multiple of four bits in the number. For example, given the binary number 1011001010, the first step would be to add two bits to the left of the number so that it contains 12 bits. The converted binary value is 001011001010. The next step is to separate the binary value into groups of four bits, e.g., 0010 1100 1010. Finally, look up these binary values in the table above and substitute the appropriate hexadecimal digits, e.g., 2CA. Contrast this with the difficulty of conversion between decimal and binary or decimal and hexadecimal!

    Since converting between hexadecimal and binary is an operation you will need to perform over and over again, you should take a few minutes and memorize the table above. Even if you have a calculator that will do the conversion for you, you'll find manual conversion to be a lot faster and more convenient when converting between binary and hex.

    Hope this helps. Good luck!

    • Commenter avatarLogin to reply the answers
  • Anonymous
    1 decade ago

    It depends on the Assembling Language you are using..each microprocessor's assembly is different....shouldn't be too hard if you know the language keywords since hex is base 16, binary is base 2, and decimal is base 10...Just keep dividing it by that certain amount, etc..

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.