Thread: 6.25 -> binary

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109

    6.25 -> binary

    I need some help with this. I'm not sure if I did it right, but converting decimal 6.25 to binary, I got 110010011. Is this right?

    I was just able to print the homework today, and I have a class tomorrow during my prof's office hours.

    I tried to do it with the divide by two method, so I'm not sure if it's right. I need help on how to convert decimal to binary when it has a decimal point. Thanks.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    6 in base 2 is
    110

    25 in base 2 is
    11011

    I don't know how to do the decimal though... unless you're using fixed point numbers. In a fixed point 8.8 representation, it would be

    00000110 00011011 (I think)
    Away.

  3. #3
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Heh. Binary conversions are easy.
    Code:
    6
    	0	1	1	0
         	8	4	2	1
    .25
    	0	1	0	0
         	1/2	1/4 	1/8 	1/16

    so - 0110.0100
    Last edited by dbgt goten; 09-09-2003 at 09:43 PM.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    This is straight from Logic and Computer Design Fundementals by Mano book:

    conversions of decimal fractions to binary:
    Code:
    (0.6875)10 -> binary
    0.6875 x 2 = 1.3750         MSD = 1
    0.3750 x 2 = 0.7500         MSD = 0
    0.7500 x 2 = 1.5000         MSD = 1
    0.5000 x 2 = 1.0000         MSD = 1
    so...
    (0.6875)10 = (0.1011)2
    hope this helps you out,

    axon

    P.S. dbgt is right!

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by dbgt goten
    Heh. Binary conversions are easy.
    Code:
    6
    	0	1	1	0
         	8	4	2	1
    .25
    	0	1	0	0
         	1/2	1/4 	1/8 	1/16

    so - 0110.0100
    that looks good, but i think i need a little more explanation of what you are doing here. i get the 1 `2 4 8 etc stuff, but the 0s and 1s that corresponds are kindof confusing me right now.
    Originally posted by axon
    This is straight from Logic and Computer Design Fundementals by Mano book:

    conversions of decimal fractions to binary:
    Code:
    (0.6875)10 -> binary
    0.6875 x 2 = 1.3750         MSD = 1
    0.3750 x 2 = 0.7500         MSD = 0
    0.7500 x 2 = 1.5000         MSD = 1
    0.5000 x 2 = 1.0000         MSD = 1
    so...
    (0.6875)10 = (0.1011)2
    hope this helps you out,

    axon

    P.S. dbgt is right!
    That times two thing looks familiar. Let me get this straight; you multiply the part behind the decimal point times two and the coefficient is what your binary number digit will be? and then you just do the part behind the decimal point no matter the coefficient?

  6. #6
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    OK, I'll try to explain how to represent decimal floating point numbers in binary here.
    you know how to convert integers like 163 which can be written this way:
    263 = 3 * 10^0 + 6 * 10^1 + 2 * 10^2
    now the same applies to floating point numbers:
    0.196 = 1 * 10^-1 + 9 * 10^-2 + 6 * 10^-3
    Now representing floating point numbers in binary goes exactly the same way, except that we use a base of 2 instead of 10, so:
    (0110.0100)2 = 0*2^3 + 1*2^2 + 1*2^1 +0*2^0 + 0*2^-1 + 1*2^-2 + 0*2^-3 +0*2^-4
    = 0 + 4 + 2 + 0 + 0 + 0.25 + 0 + 0 = (6.25)10

    edit:
    looks like I can't use html here

  7. #7
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Originally posted by alpha
    Let me get this straight; you multiply the part behind the decimal point times two and the coefficient is what your binary number digit will be? and then you just do the part behind the decimal point no matter the coefficient?
    yes, that is correct. Notice that after multiplying the fraction by 2, the result will always either have a 1.something or a 0.something, nothing else.

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  8. #8
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Originally posted by alpha
    that looks good, but i think i need a little more explanation of what you are doing here. i get the 1 `2 4 8 etc stuff, but the 0s and 1s that corresponds are kindof confusing me right now.
    Basicly we know that to the left of a decimal binary digits represent a value of double the previous digit. IE:
    1, 2, 4, 8, 16, 32, 64, 128 etc
    But to the right of the decimal its the same thing, but with 1 over the value IE:
    1/2, 1/4, 1/8, 1/16, 1/32, 1/64, 1/128 etc
    All these values are fractions:
    1/2 = .5
    1/4 = .25
    etc.
    This conversion method is better used from binary to decimal and not vice versa - becuase when coming from decimal to binary you arnt garanteed a nice decimal value.

    convert 1.11 to decimal:
    1 + 1/2 + 1/4 = 1.75

    The only reason I converted from decimal to binary was becuase I recognized .25 as the easy 1/4.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary File -> End of File
    By wots_guge in forum C Programming
    Replies: 5
    Last Post: 06-02-2006, 09:39 AM
  2. Binary data -> istream
    By Magos in forum C++ Programming
    Replies: 8
    Last Post: 01-24-2005, 02:57 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. ASCII -> Binary
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-13-2001, 05:51 AM