Decimal Points and Binary Points

This is a discussion on Decimal Points and Binary Points within the A Brief History of Cprogramming.com forums, part of the Community Boards category; How can you take 100.1 (binary) and get 4.5 (decimal) I understand that: 100(binary) = 4.0(dec) because that is the ...

  1. #1
    Shadow12345
    Guest

    Decimal Points and Binary Points

    How can you take 100.1 (binary) and get 4.5 (decimal)

    I understand that:
    100(binary) = 4.0(dec) because that is the same as saying there are no ones, no twos, and one four.

    I also understand 1101 to mean 13 because there it is 1 + (0 * 2) + (1 * 4) + (1 * 8).

    I don't understand how 100.1(bin) can equal 4.5(dec). I would have thought it to mean 4.1

    Can you have a binary number be something like 2021 which in decimal would be (1 * 1) + (2*2) + (0 * 4) + (2 * 8). It is still in binary powers, it is just saying how many of each power exists.

    EDIT
    and btw this is from a book, in case u cared!

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    You seem to mixing binary and decimal. Just because you go to the right of the 'decimal' point, doesn't mean you switch back to decimal again.

    100.1 is 4.5 because 1 is half of 10(b), in the same way 5 is half 10(d).

    Here's a question for you. How do you express 4.2 in binary terms?

  3. #3
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    >Can you have a binary number be something like 2021

    I don't follow you. Are saying can 2021 be a binary number? The answer is no, there is no digit 2 in binary.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Assume this is a number in binary:

    abc.def

    Where each letter is a digit, 1 or 0.
    To get the decimal number you do this:

    (a * 2^2) + (b * 2^1) + (c * 2^0) + (d * 2^-1) + (e * 2^-2) + (f * 2^-3)
    a*4 + b*2 + c*1 + d*(1/2) + e*(1/4) + f*(1/8)

    The power is positive on the left side and negative on the right side, and incrementing by 1 in both directions from the decimal point.
    Last edited by Magos; 11-06-2002 at 01:03 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Shadow12345
    100.01?

    I don't really get it
    100.01

    |
    v

    (1 * 4) + (0 * 2) + (0 * 1) + (0 * (1/2)) + (1 * (1/4)) =
    4 + (1/4) =
    4.25
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Shadow12345
    Guest
    HOw do i take 4.2 and turn that into binary?
    I'm still confused lol

  7. #7
    Shadow12345
    Guest
    4.2 = 100.01

  8. #8
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    I get 4.2 to be 100.0011

    To get the fractional value you keep multiplying the fractional value until you get the same value started with or you have reached the required precision.

    e.g 0.2 to binary.

    0.2 * 16 = 3.2
    0.2 * 16 = 3.2

    As you keep multiplying you take the fractional value from the result to the next multiplication. You could multiply the fractional value by 2, but it would take a bit longer. Once you have finished multiplying you take each significant digit, and convert to binary. Since we have a 3, 3 in binary is 0011 (4 binary bits to one hex). Notice how we got the same answer as what we started with! You then stop.
    Be a leader and not a follower.

  9. #9
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Keep in mind that not all numbers can be represented exactly. For example 1/3 = 0.3333333.... in decimal. Binary numbers have the same characteristics for certain numbers also.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  10. #10
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    In decimal numbers, the first digit (in the decimal part) represents 1/10, the second 1/100, the third 1/1000 and so on...

    In other words:
    10^-1, 10^-2, 10^-3 and so on...

    So it isn't so hard to realize that, in binary numbers, the first digit after (in the decimal part) represents 1/2, the second 1/4, the third 1/8 and so on...

    In other words:
    2^-1, 2^-2, 2^-3 and so on...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning Memory, Ins and Outs?
    By Zoiked in forum C Programming
    Replies: 1
    Last Post: 08-27-2007, 05:43 PM
  2. Replies: 0
    Last Post: 11-04-2006, 11:07 AM
  3. C++ Binary Tree Maximum Value function
    By krizam in forum C++ Programming
    Replies: 4
    Last Post: 12-05-2005, 09:52 AM
  4. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21