Shop OBEX P1 Docs P2 Docs Learn Events
Binary Numbers to Decimals — Parallax Forums

Binary Numbers to Decimals

ArchiverArchiver Posts: 46,084
edited 2000-06-02 01:59 in General Discussion
Hello everyone I'm trying to figure out how to convert decimals to
binary numnbers, binary to hexadecimal, and decimal to hexdecimal
Is there an equation I can use to convert this. Please help.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2000-05-31 20:56
    Each binary digit represents a power of two. Let's do a 4-bit number:

    2**3 2**2 2**1 2**0

    (2**3 means 2 to the third power)

    So say you have 10 decimal. Start at the left, 2**3 = 8. 8<=10 so set that
    bit to 1. 10-8 is 2, so you have 2 left.

    Next is 2**2 = 4. 4>2 so set that bit to 0.

    2**1 is 2 and 2<=2 so set this bit to 1 and subtract. 2-2 = 0 so you are
    done.

    1010

    =====
    Going the opposite way is to just add the bits.
    0111
    2**2 + 2**1 + 2**0 = 4+2+1 = 7

    ====

    Hex is easy because every 4 bits is one hex digit.
    0=0000 1=0001 2=0010 3=0011 4=0100 5=0101 6=0110 7=0111
    8=1000 9=1001 A=1010 B=1011 C=1100 D=1101 E=1110 F=1111

    10100111 = 1010 0111 = A7

    39 = 0011 1001

    ====

    You can convert between hex and decimal by going to binary and then to
    decimal. Or...

    Convert each digit to 0 to 15 and multiply by 16**n where n is the position.

    So 64 hex is 6 * 16**1 + 4 * 16**0 = 6 * 16 + 4 * 1 = 96 + 4 = 100

    20F0 is 2 * 16**3 + 0 * 16**2 + 15 * 16**1 + 0 * 16**0 = 2 * 4096 + 0 + 15 *
    16 + 0 = 8432

    ===

    Many cheap calculators will do this for you. Also if you start the Windows
    calculator and select View | Scientific, you can do conversions that way.

    Regards,

    Al Williams
    AWC
    *8 channels of pulse output: http://www.al-williams.com/awce/pak8.htm



    >
    Original Message
    > From: reggie19523@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=h0H13jGyJdUAL0OMJvisq5dY5QxVu2PPCLdUQc5_9JCKrSZz_wvJmQFLCxj5QYNS0BYd2ZVZMyHvYQKfvQ]reggie19523@y...[/url
    > Sent: Wednesday, May 31, 2000 2:24 PM
    > To: basicstamps@egroups.com
    > Subject: [noparse][[/noparse]basicstamps] Binary Numbers to Decimals
    >
    >
    > Hello everyone I'm trying to figure out how to convert decimals to
    > binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    > Is there an equation I can use to convert this. Please help.
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-31 21:01
    what are you trying to do display this or read a RTC ? there are
    modifiers that will do the work for you

    Al Williams wrote:
    >
    > Each binary digit represents a power of two. Let's do a 4-bit number:
    >
    > 2**3 2**2 2**1 2**0
    >
    > (2**3 means 2 to the third power)
    >
    > So say you have 10 decimal. Start at the left, 2**3 = 8. 8<=10 so set that
    > bit to 1. 10-8 is 2, so you have 2 left.
    >
    > Next is 2**2 = 4. 4>2 so set that bit to 0.
    >
    > 2**1 is 2 and 2<=2 so set this bit to 1 and subtract. 2-2 = 0 so you are
    > done.
    >
    > 1010
    >
    > =====
    > Going the opposite way is to just add the bits.
    > 0111
    > 2**2 + 2**1 + 2**0 = 4+2+1 = 7
    >
    > ====
    >
    > Hex is easy because every 4 bits is one hex digit.
    > 0=0000 1=0001 2=0010 3=0011 4=0100 5=0101 6=0110 7=0111
    > 8=1000 9=1001 A=1010 B=1011 C=1100 D=1101 E=1110 F=1111
    >
    > 10100111 = 1010 0111 = A7
    >
    > 39 = 0011 1001
    >
    > ====
    >
    > You can convert between hex and decimal by going to binary and then to
    > decimal. Or...
    >
    > Convert each digit to 0 to 15 and multiply by 16**n where n is the position.
    >
    > So 64 hex is 6 * 16**1 + 4 * 16**0 = 6 * 16 + 4 * 1 = 96 + 4 = 100
    >
    > 20F0 is 2 * 16**3 + 0 * 16**2 + 15 * 16**1 + 0 * 16**0 = 2 * 4096 + 0 + 15 *
    > 16 + 0 = 8432
    >
    > ===
    >
    > Many cheap calculators will do this for you. Also if you start the Windows
    > calculator and select View | Scientific, you can do conversions that way.
    >
    > Regards,
    >
    > Al Williams
    > AWC
    > *8 channels of pulse output: http://www.al-williams.com/awce/pak8.htm
    >
    > >
    Original Message
    > > From: reggie19523@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=qsJ0agy8hOyR6uqtpyE85cX1wbxs8xfi08UKNC0iRQ78GwqMhIGDJ0tf4EUVspXzujow6XimqDeEfbQRpBc]reggie19523@y...[/url
    > > Sent: Wednesday, May 31, 2000 2:24 PM
    > > To: basicstamps@egroups.com
    > > Subject: [noparse][[/noparse]basicstamps] Binary Numbers to Decimals
    > >
    > >
    > > Hello everyone I'm trying to figure out how to convert decimals to
    > > binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    > > Is there an equation I can use to convert this. Please help.
    > >
    > >
    > >
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-31 21:08
    here is something I use just type the hex,bin,dec number on the first
    line and you will get the value in all three formats using the debug
    screen and a stamp of course.
    I wish someone would add this to the stamp software or write a VB
    program for doing this and make it easy when programming?? AL ??

    w0 =
    DEBUG ? W0
    debug hex ? w0
    debug BIN ? w0






    LarryGaminde wrote:
    >
    > what are you trying to do display this or read a RTC ? there are
    > modifiers that will do the work for you
    >
    > Al Williams wrote:
    > >
    > > Each binary digit represents a power of two. Let's do a 4-bit number:
    > >
    > > 2**3 2**2 2**1 2**0
    > >
    > > (2**3 means 2 to the third power)
    > >
    > > So say you have 10 decimal. Start at the left, 2**3 = 8. 8<=10 so set that
    > > bit to 1. 10-8 is 2, so you have 2 left.
    > >
    > > Next is 2**2 = 4. 4>2 so set that bit to 0.
    > >
    > > 2**1 is 2 and 2<=2 so set this bit to 1 and subtract. 2-2 = 0 so you are
    > > done.
    > >
    > > 1010
    > >
    > > =====
    > > Going the opposite way is to just add the bits.
    > > 0111
    > > 2**2 + 2**1 + 2**0 = 4+2+1 = 7
    > >
    > > ====
    > >
    > > Hex is easy because every 4 bits is one hex digit.
    > > 0=0000 1=0001 2=0010 3=0011 4=0100 5=0101 6=0110 7=0111
    > > 8=1000 9=1001 A=1010 B=1011 C=1100 D=1101 E=1110 F=1111
    > >
    > > 10100111 = 1010 0111 = A7
    > >
    > > 39 = 0011 1001
    > >
    > > ====
    > >
    > > You can convert between hex and decimal by going to binary and then to
    > > decimal. Or...
    > >
    > > Convert each digit to 0 to 15 and multiply by 16**n where n is the position.
    > >
    > > So 64 hex is 6 * 16**1 + 4 * 16**0 = 6 * 16 + 4 * 1 = 96 + 4 = 100
    > >
    > > 20F0 is 2 * 16**3 + 0 * 16**2 + 15 * 16**1 + 0 * 16**0 = 2 * 4096 + 0 + 15 *
    > > 16 + 0 = 8432
    > >
    > > ===
    > >
    > > Many cheap calculators will do this for you. Also if you start the Windows
    > > calculator and select View | Scientific, you can do conversions that way.
    > >
    > > Regards,
    > >
    > > Al Williams
    > > AWC
    > > *8 channels of pulse output: http://www.al-williams.com/awce/pak8.htm
    > >
    > > >
    Original Message
    > > > From: reggie19523@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=WOB-TiZsD4ui3cRrQ8iQbBHcbswtv5NeUGB8XCbfBvAeb4Bd5NKJ0LiJhU-AaCM-JtcUfcK5k4jkAZbaMQvi8Q]reggie19523@y...[/url
    > > > Sent: Wednesday, May 31, 2000 2:24 PM
    > > > To: basicstamps@egroups.com
    > > > Subject: [noparse][[/noparse]basicstamps] Binary Numbers to Decimals
    > > >
    > > >
    > > > Hello everyone I'm trying to figure out how to convert decimals to
    > > > binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    > > > Is there an equation I can use to convert this. Please help.
    > > >
    > > >
    > > >
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-31 22:05
    sorry Al I did not read the last line you wrote the windows calculator
    works great!!

    LarryGaminde wrote:
    >
    > here is something I use just type the hex,bin,dec number on the first
    > line and you will get the value in all three formats using the debug
    > screen and a stamp of course.
    > I wish someone would add this to the stamp software or write a VB
    > program for doing this and make it easy when programming?? AL ??
    >
    > w0 =
    > DEBUG ? W0
    > debug hex ? w0
    > debug BIN ? w0
    >
    > LarryGaminde wrote:
    > >
    > > what are you trying to do display this or read a RTC ? there are
    > > modifiers that will do the work for you
    > >
    > > Al Williams wrote:
    > > >
    > > > Each binary digit represents a power of two. Let's do a 4-bit number:
    > > >
    > > > 2**3 2**2 2**1 2**0
    > > >
    > > > (2**3 means 2 to the third power)
    > > >
    > > > So say you have 10 decimal. Start at the left, 2**3 = 8. 8<=10 so set that
    > > > bit to 1. 10-8 is 2, so you have 2 left.
    > > >
    > > > Next is 2**2 = 4. 4>2 so set that bit to 0.
    > > >
    > > > 2**1 is 2 and 2<=2 so set this bit to 1 and subtract. 2-2 = 0 so you are
    > > > done.
    > > >
    > > > 1010
    > > >
    > > > =====
    > > > Going the opposite way is to just add the bits.
    > > > 0111
    > > > 2**2 + 2**1 + 2**0 = 4+2+1 = 7
    > > >
    > > > ====
    > > >
    > > > Hex is easy because every 4 bits is one hex digit.
    > > > 0=0000 1=0001 2=0010 3=0011 4=0100 5=0101 6=0110 7=0111
    > > > 8=1000 9=1001 A=1010 B=1011 C=1100 D=1101 E=1110 F=1111
    > > >
    > > > 10100111 = 1010 0111 = A7
    > > >
    > > > 39 = 0011 1001
    > > >
    > > > ====
    > > >
    > > > You can convert between hex and decimal by going to binary and then to
    > > > decimal. Or...
    > > >
    > > > Convert each digit to 0 to 15 and multiply by 16**n where n is the
    position.
    > > >
    > > > So 64 hex is 6 * 16**1 + 4 * 16**0 = 6 * 16 + 4 * 1 = 96 + 4 = 100
    > > >
    > > > 20F0 is 2 * 16**3 + 0 * 16**2 + 15 * 16**1 + 0 * 16**0 = 2 * 4096 + 0 + 15
    *
    > > > 16 + 0 = 8432
    > > >
    > > > ===
    > > >
    > > > Many cheap calculators will do this for you. Also if you start the Windows
    > > > calculator and select View | Scientific, you can do conversions that way.
    > > >
    > > > Regards,
    > > >
    > > > Al Williams
    > > > AWC
    > > > *8 channels of pulse output: http://www.al-williams.com/awce/pak8.htm
    > > >
    > > > >
    Original Message
    > > > > From: reggie19523@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=OlnjNd2lL6qJEu78xWCOjVOjGSP4lLYQyS29MlDeSqUd_rUcMQmFfyQYtvX5LNZfoeCxmyR4sUC5WdCEkG8R]reggie19523@y...[/url
    > > > > Sent: Wednesday, May 31, 2000 2:24 PM
    > > > > To: basicstamps@egroups.com
    > > > > Subject: [noparse][[/noparse]basicstamps] Binary Numbers to Decimals
    > > > >
    > > > >
    > > > > Hello everyone I'm trying to figure out how to convert decimals to
    > > > > binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    > > > > Is there an equation I can use to convert this. Please help.
    > > > >
    > > > >
    > > > >
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-31 22:08
    In a message dated 5/31/00 2:26:19 PM Central Daylight Time,
    reggie19523@y... writes:

    > Hello everyone I'm trying to figure out how to convert decimals to
    > binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    > Is there an equation I can use to convert this. Please help.

    Where are you wanting to do the conversions? You don't need to in the Stamp
    since the SEROUT and DEBUG modifiers (BIN, HEX and DEC) take care of things
    for you.
  • ArchiverArchiver Posts: 46,084
    edited 2000-05-31 22:09
    By odd coincidence, I was writing some course notes for a VB lecture and
    needed an example so this is it. Get it at www.al-williams.com/number.exe

    Type in either decimal, binary, or hex and it fills in the other two. Copy
    and paste if you like. The binary is only good to 16 bits. Probably ought to
    do a better job error and range checking. You need the VB runtime. If you
    don't have it, download and install the BS1 emulator and you should get all
    the files you need.

    Really not a very useful program, but I needed an example anyway so....

    Enjoy.

    Al Williams
    AWC
    * Floating point math for the Stamp, PIC, SX, or any microcontroller:
    http://www.al-williams.com/awce/pak1.htm


    >
    Original Message
    > From: LarryGaminde [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=duWv0B78CXqo2Ze7adsYaafEcXx1NlqMEeOeR_X9xqHDDrDla27YzxVRrDupWHe9gPugivWcr8msA6JL]lgaminde@t...[/url
    > Sent: Wednesday, May 31, 2000 3:09 PM
    > To: basicstamps@egroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] Binary Numbers to Decimals
    >
    >
    > here is something I use just type the hex,bin,dec number on the first
    > line and you will get the value in all three formats using the debug
    > screen and a stamp of course.
    > I wish someone would add this to the stamp software or write a VB
    > program for doing this and make it easy when programming?? AL ??
    >
    > w0 =
    > DEBUG ? W0
    > debug hex ? w0
    > debug BIN ? w0
    >
    >
    >
    >
    >
    >
    > LarryGaminde wrote:
    > >
    > > what are you trying to do display this or read a RTC ? there are
    > > modifiers that will do the work for you
    > >
    > > Al Williams wrote:
    > > >
    > > > Each binary digit represents a power of two. Let's do a 4-bit number:
    > > >
    > > > 2**3 2**2 2**1 2**0
    > > >
    > > > (2**3 means 2 to the third power)
    > > >
    > > > So say you have 10 decimal. Start at the left, 2**3 = 8.
    > 8<=10 so set that
    > > > bit to 1. 10-8 is 2, so you have 2 left.
    > > >
    > > > Next is 2**2 = 4. 4>2 so set that bit to 0.
    > > >
    > > > 2**1 is 2 and 2<=2 so set this bit to 1 and subtract. 2-2 = 0
    > so you are
    > > > done.
    > > >
    > > > 1010
    > > >
    > > > =====
    > > > Going the opposite way is to just add the bits.
    > > > 0111
    > > > 2**2 + 2**1 + 2**0 = 4+2+1 = 7
    > > >
    > > > ====
    > > >
    > > > Hex is easy because every 4 bits is one hex digit.
    > > > 0=0000 1=0001 2=0010 3=0011 4=0100 5=0101 6=0110 7=0111
    > > > 8=1000 9=1001 A=1010 B=1011 C=1100 D=1101 E=1110 F=1111
    > > >
    > > > 10100111 = 1010 0111 = A7
    > > >
    > > > 39 = 0011 1001
    > > >
    > > > ====
    > > >
    > > > You can convert between hex and decimal by going to binary and then to
    > > > decimal. Or...
    > > >
    > > > Convert each digit to 0 to 15 and multiply by 16**n where n
    > is the position.
    > > >
    > > > So 64 hex is 6 * 16**1 + 4 * 16**0 = 6 * 16 + 4 * 1 = 96 + 4 = 100
    > > >
    > > > 20F0 is 2 * 16**3 + 0 * 16**2 + 15 * 16**1 + 0 * 16**0 = 2 *
    > 4096 + 0 + 15 *
    > > > 16 + 0 = 8432
    > > >
    > > > ===
    > > >
    > > > Many cheap calculators will do this for you. Also if you
    > start the Windows
    > > > calculator and select View | Scientific, you can do
    > conversions that way.
    > > >
    > > > Regards,
    > > >
    > > > Al Williams
    > > > AWC
    > > > *8 channels of pulse output: http://www.al-williams.com/awce/pak8.htm
    > > >
    > > > >
    Original Message
    > > > > From: reggie19523@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=o5f87HY5ol-mxywQofc1ujYojnPe6BhJcJ3MPxhh5RbuPCaXASw9Rme2qT8PzcuET6MyN5PQhj9pi0w]reggie19523@y...[/url
    > > > > Sent: Wednesday, May 31, 2000 2:24 PM
    > > > > To: basicstamps@egroups.com
    > > > > Subject: [noparse][[/noparse]basicstamps] Binary Numbers to Decimals
    > > > >
    > > > >
    > > > > Hello everyone I'm trying to figure out how to convert decimals to
    > > > > binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    > > > > Is there an equation I can use to convert this. Please help.
    > > > >
    > > > >
    > > > >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-01 03:53
    The TI-34 calculator ~$19 will do that with ease. I'm sure there are others
    also. Works great..... ==Mac==

    At 07:24 PM 5/31/00 -0000, you wrote:
    >Hello everyone I'm trying to figure out how to convert decimals to
    >binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    >Is there an equation I can use to convert this. Please help.
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2000-06-02 01:59
    The calculator's always easiest, but just in case you really wanted
    to know, there are formulas:

    Binary/Decimal:
    Each binary digit is raised to the next power of 2 when converting
    to decimal.

    for an 8 digit number:
    2^7, 2^6, 2^5, 2^4, 2^3, 2^2, 2^1, 2^0
    128, 64, 32, 16, 8, 4, 2, 1 (ok, I think you get the point)

    for example:

    10100101

    1x128 + 0x64 + 1x32 + 0x16 + 0x8 + 1x4 + 0x2 + 1x1 or simply
    1x128 + 1x32 + 1x4 + 1x1 = 165



    Binary/Hexadecimal:
    Each group of 4 binary digits forms one hexadecimal digit

    10100101 --or-- 1010 0101

    Use the above calculation for binary to decimal to determine its
    decimal equivalent, then convert to hex.

    1010 = 1x8 + 1x2 = 10 = A
    0101 = 1x4 + 1x1 = 5 = 5

    Thus, the hexadecimal equivalent of 10100101 is A5.

    If you don't believe me (or your own calculations), check it on your
    calculator. Of course, by that time, you might as well have done
    the whole thing on the calculator and saved yourself some time. [noparse]:)[/noparse]

    ~JL

    The TI-34 calculator ~$19 will do that with ease. I'm sure there are
    others
    also. Works great..... ==Mac==

    At 07:24 PM 5/31/00 -0000, you wrote:
    >Hello everyone I'm trying to figure out how to convert decimals to
    >binary numnbers, binary to hexadecimal, and decimal to hexdecimal
    >Is there an equation I can use to convert this. Please help.
    >
    >
    >
    >
Sign In or Register to comment.