1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A guide to binary, decimal conversions

  1. Sep 23, 2013 #1
    Hello guys, I have seen some post here that were asking about binary to decimal conversions and signed unsigned binary numbers and such, so I decided to make this thread as a guide. I know it's pretty easy, but having a guide here can always be helpful and reduces repetitions:wink:
    If this isn't allowed please close it immediately.

    Binary to Decimal conversion

    A binary number is a number written in the base 2, using only 1s and 0s, a decimal number can be written as such:

    X=[itex]a_{0}[/itex]*[itex]2^{0}[/itex]+[itex]a_{1}[/itex]*[itex]2^{1}[/itex]+[itex]a_{2}[/itex]*[itex]2^{2}[/itex]......[itex]a_{n-1}[/itex]*[itex]2^{n-1}[/itex] (1)

    Where n is the number of bits (number of ones and zeros) used to write the number in binary:

    If n=8, and the binary number is 11010010 then:

    [itex]a_{0}[/itex]=0.
    [itex]a_{1}[/itex]=1.
    [itex]a_{2}[/itex]=0.
    [itex]a_{3}[/itex]=0.
    [itex]a_{4}[/itex]=1.
    [itex]a_{5}[/itex]=0.
    [itex]a_{6}[/itex]=1.
    [itex]a_{7}[/itex]=1.

    Keep in mind that we read from right to left the [itex]a_{i}[/itex] in the binary number.
    Replace the [itex]a_{i}[/itex] by their values in (1) and there you go, you would have converted your binary number to a decimal one!

    In our example:

    D=0*[itex]2^{0}[/itex]+1*[itex]2^{1}[/itex]+0*[itex]2^{2}[/itex]+0*[itex]2^{3}[/itex]+1*[itex]2^{4}[/itex]+0*[itex]2^{5}[/itex]+1*[itex]2^{6}[/itex]+1*[itex]2^{7}[/itex] =210.

    Decimal to binary conversion


    Here's a general method (Bear in mind there are other methods):

    Take your n bit number (let's consider 186 to add diversity, and in this case it's 8 bits):

    Is 186 >= [itex]2^{7}[/itex]=128? Yes.
    thus: [itex]a_{7}[/itex]=1.

    Now take 186 and substract [itex]2^{7}[/itex] => 58.
    And redo the operation:

    Is 58 >= [itex]2^{6}[/itex]=64? No.
    thus: [itex]a_{6}[/itex]=0.

    Do not substract anything since 58<64

    Now go to the 3rd digit.

    Is 58 >= [itex]2^{5}[/itex]=32? Yes.
    thus [itex]a_{5}[/itex]=1.

    58-32=26.

    Is 26 >= [itex]2^{4}[/itex]=16? Yes.
    thus [itex]a_{4}[/itex]=1.

    Is 26-16=10 > [itex]2^{3}[/itex]=8? Yes.
    thus [itex]a_{3}[/itex]=1.

    Is 10-8 >= [itex]2^{2}[/itex]=4? No.
    thus [itex]a_{2}[/itex]=0.

    Is 10-8>= [itex]2^{1}[/itex]=2? Yes.
    thus [itex]a_{2}[/itex]=1.

    Is 2-2 >= [itex]2^{0}[/itex]=1? No.
    thus the last digit on the right is 0.

    Result: 10111010

    Verification: 128+0+32+16+8+0+2+0=186. The operation is correct.

    Unsigned/Signed integers

    In the computer and telecommunication world, everything is coded in binary, but in a lot of electronic and logical circuits, we might need to represent negative numbers, so how to do that?

    An Unsigned number is the regular binary number, for example:
    The Unsigned binary number 11111111, is 255.

    Since we have spoken about an Unsigned number, then there must be a signed number/representation.

    What basically this method do, is splitting up the interval into 2.
    Consider n=8 bits.
    An Unsigned number can go from 00000000 to 11111111 so from 0 to 255: [0:255]
    The signed number method goes by the following: Instead of using the interval [0:255] why not use [-127:127]? 127 represent a decimal number that can be written as 1111111 so 7 bits, then why not use the single last bit (highest weight) and make it represent a "sign". If it's 1 then the number is negative, if 0 the number is positive.

    Let us illustrate with an example:
    -102:

    First: Transform 102 (without the "-") to binary.
    You get: 0 1100110 (Note: 102 can be written on 7 bits, and the remaining 1 bit is used for the sign).

    Secondly: Check the original sign of the number,
    It's negative hence instead of putting a 0 at the beginning, we put 1
    We finally get

    1 1100110 which represents the number -102.
    Obviously in the problem that you are asked, the instructor would need to specify if you're dealing with Unsigned or Signed binary numbers so you'll know if 11100110 represents -102 (Signed) or 230 which might cause an ambiguity.

    Regards,
    Magna Visus.
     
    Last edited: Sep 23, 2013
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?



Similar Discussions: A guide to binary, decimal conversions
  1. Guided waves - MMI (Replies: 0)

  2. Binary Hypothesis test (Replies: 0)

Loading...