converting decimal values to binary coded decimal?

Discussion in 'Web Design & Coding' started by forcer, Nov 26, 2003.

  1. forcer

    forcer OSNN Senior Addict

    Messages:
    413
    i have to convert decimal values to binary coded decimal

    for instance if i have the number 32 converting that to binary would be 00110010

    but whats the outcome if i convert 32 to "binary coded decimal"
     
  2. Petros

    Petros Thief IV

    Messages:
    3,038
    Location:
    Pacific Northwest
    In BCD, each digit of a number is represented by a four-bit binary, e.g. 134 becomes 0001 0011 0100
     
  3. forcer

    forcer OSNN Senior Addict

    Messages:
    413
    thats how i was converting to binary. if thats how u convert to BCD how do u convert to "binary" (not bcd)
     
  4. mbx

    mbx Guest

    32 in binary is 00100000.


    to convert decimal to binary
    each byte has 8 bits.
    from right to left the bits are 1,2,4,8,16,32,64,128

    so 32 (00100000) is made up of
    no 128s
    no 64s
    1 32
    no 16s
    no 8s
    no 4s
    no 2
    and no 1s

    and number like 169 in binary would be
    1 128 (1)
    no 64 (0)
    1 32 (1)
    no 16 (0)
    1 8 (1)
    no 4 (0)
    no 2 (0)
    1 1 (1)

    so reading from the top gives you 10101001 (or 128+32+8+1)

    hope that helps
     
  5. Petros

    Petros Thief IV

    Messages:
    3,038
    Location:
    Pacific Northwest
    Oops sorry...i was a lil confused and thought you wanted BCD...that's what I get for not reading posts. :) Binary just follows the same 1-2-4-8-16-32-etc. progression, though, it's just that the sky is the limit on how many digits you can have.
     
  6. forcer

    forcer OSNN Senior Addict

    Messages:
    413
    many thanx. now i wont fail my assignment..

    theres so many binary bcd hexadecimal etc... i got way confused.

    thanx agen
     
  7. forcer

    forcer OSNN Senior Addict

    Messages:
    413
    ok so if i was converting 41 it would be:

    41 – 00101001

    1 + 8 + 32 = 41

    ??????
     
  8. Petros

    Petros Thief IV

    Messages:
    3,038
    Location:
    Pacific Northwest
    Right on!
     
  9. yoyo

    yoyo _________________

    Messages:
    1,557
    And if you want to cheat, start the Windows calculator in scientific view. ;)
     
  10. Nitris

    Nitris Guest

    Conversion of base 10 to other bases.

    Repeatedly divide the base 10 number by the base. Keep track of the remainders and read the remainders top to bottom.

    Code:
    abcd(base 10) = _________(base n)
    
    [IMG]http://otto.normandale.edu/csci1101/conv1.gif[/IMG] 
    
    abcd(base 10) = r4 r3 r2 r1 (base n)
    
    1310 = _________(base 2)
    
    [IMG]http://otto.normandale.edu/csci1101/conv2.gif[/IMG] 
    
    1310 = 1101(base 2)
    
    hope this helps :D