Decimal to Binary help! Please!

Poontos

Platinum Member
Mar 9, 2000
2,799
0
0
Hi ya's,

Here's an excercise that I am stuck on:

Task: Practice converting the following decimal values of the IP address 209.114.58.165 to the binary octet equivalent.

Explanation: Look at the Decimal value and then subtract binary values starting from 128 (the highest value binary bit). If the number is larger than 128 then put a one in the first position binary number bit status. Subtract 128 from the number and then see if there is a 64 left. If there is put a one there otherwise put a zero and see if there is a 32. Continue until all 8 bits are defined as either a zero or a one.

1. Solve the 1st , 2nd , 3rd and 4th octet Decimal value to binary bit number
Exponent 27 26 25 24 23 22 21 20
Bit Position 8 7 6 5 4 3 2 1
Value 128 64 32 16 8 4 2 1

Binary Number Bit Status

1st Octet Binary Value: ________________


Ok, so I did the following:

209 > then 128, so I put a 1
209 - 128 = 81, so I put a 1
81 - 64 = 17, so I put a 0
17 - 32 = -15, so I put a 0?

Here's where it starts to get wrong... the proper binary value of 209 is 11010001, but I`m not getting there manually.

Can anyone help?


Thanks!

 

Shaka

Senior member
Oct 13, 1999
608
0
0
209 - 128 = 81 so 1
81 - 64 = 17 so 1
17 - 32 = -15 so 0
17 - 16 = 1 so 1
1 - 8 = -7 so 0
1- 4 = -3 so 0
1-2 = -1 so 0
1-1 = 0 so 1

Answer is 11010001.

Clarification: The method above tries to figure out which powers of 2 are needed to sum up to 209.
( 1 * 128 ) +
( 1 * 64 ) +
( 0 * 32 ) +
( 1 * 16 ) +
( 0 * 8 ) +
( 0 * 4 ) +
( 0 * 2 ) +
( 1 * 1 ) = 209 equivalent to:

( 1 * 2^7 ) +
( 1 * 2^6 ) +
( 0 * 2^5 ) +
( 1 * 2^4 ) +
( 0 * 2^3 ) +
( 0 * 2^2 ) +
( 0 * 2^1 ) +
( 1 * 2^0 ) = 209 equivalent to:

As you can see, the 1's and 0's of the 2nd column ( aka the column of text after the left parentheses ), comprise the binary equivalent of 209.

The numeric method you were using tries to figure out those 1's and 0's. From your post, it seemed as if you were getting it correct, even the - 15.
Perhaps it'd be a good idea if you went over the fundamentals of the decimal system. That may be your stumbling block to understanding decimal to binary conversion.
 

Ameesh

Lifer
Apr 3, 2001
23,686
0
0
binary digits are powers of 2 so the prgression goes like this:



1024 512 256 128 64 32 16 8 4 2 1

(2^10) + (2^9) + (2^8) + (2^7) + (2^6) + (2^5) + (2^4) + (2^3) + (2^2) + (2^1) + (2^0)

0 0 0 1 1 0 1 0 0 0 1



(2^7) + (2^6) + (2^4) + (2^0) = 128 + 64 +16 +1 = 209 (W5) :D



understand?
 

Ameesh

Lifer
Apr 3, 2001
23,686
0
0
stupid spacing in forums it all looked right before, poontos just line up the numbers in columns.
 

Poontos

Platinum Member
Mar 9, 2000
2,799
0
0
Thanks Ameesh! Does Shaka's response make sense? I`m lost on that one...

Just going through yours now... gimme a minute.