# Homework Help: A guide to binary, decimal conversions

1. Sep 23, 2013

### Magna Visus

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
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=$a_{0}$*$2^{0}$+$a_{1}$*$2^{1}$+$a_{2}$*$2^{2}$......$a_{n-1}$*$2^{n-1}$ (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:

$a_{0}$=0.
$a_{1}$=1.
$a_{2}$=0.
$a_{3}$=0.
$a_{4}$=1.
$a_{5}$=0.
$a_{6}$=1.
$a_{7}$=1.

Keep in mind that we read from right to left the $a_{i}$ in the binary number.
Replace the $a_{i}$ 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*$2^{0}$+1*$2^{1}$+0*$2^{2}$+0*$2^{3}$+1*$2^{4}$+0*$2^{5}$+1*$2^{6}$+1*$2^{7}$ =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 >= $2^{7}$=128? Yes.
thus: $a_{7}$=1.

Now take 186 and substract $2^{7}$ => 58.
And redo the operation:

Is 58 >= $2^{6}$=64? No.
thus: $a_{6}$=0.

Do not substract anything since 58<64

Now go to the 3rd digit.

Is 58 >= $2^{5}$=32? Yes.
thus $a_{5}$=1.

58-32=26.

Is 26 >= $2^{4}$=16? Yes.
thus $a_{4}$=1.

Is 26-16=10 > $2^{3}$=8? Yes.
thus $a_{3}$=1.

Is 10-8 >= $2^{2}$=4? No.
thus $a_{2}$=0.

Is 10-8>= $2^{1}$=2? Yes.
thus $a_{2}$=1.

Is 2-2 >= $2^{0}$=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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted