# Binary for dummies help

#### OutHouse

##### Lifer
ok i know how to convert binary to decimal, but HOW THE HELL DO YOU CONVERT DECIMAL TO BINARY.

say i want to convert 172.16.100.4 to binary the hard way of pen and paper what is the process.

#### Malak

##### Lifer
You use a calculator that does it for you.

#### OutHouse

##### Lifer
Originally posted by: Malak
You use a calculator that does it for you.

yes i know and that is how i forgot how to do this.

#### her209

##### No Lifer
Here's a hint (numbers in base 10):

1057 = 1*1000 + 0*100 + 5*10 + 7*1

#### TheStu

Moderator
that could work....

172-128 = 44 so 1
44-64 = -20 so 0
44-32 = 12 so 1
12-16 = -4 so 0
12-8 = 4 so 1
4-4 = 0 so 1
0-2 = -2 so 0
0-1 = -1 so 0
10101100

easy peasy

#### OutHouse

##### Lifer
Originally posted by: TheStu
that could work....

172-128 = 44 so 1
44-64 = -20 so 0
44-32 = 12 so 1
12-16 = -4 so 0
12-8 = 4 so 1
4-4 = 0 so 1
0-2 = -2 so 0
0-1 = -1 so 0
10101100

easy peasy

you just confused the crap out of me.

#### TheStu

Moderator
ok see... you pick one of the numbers just slightly smaller than the number you have chosen... if it is IP addresses they cant get any bigger than 128 so you start there. So you take your number and subtract 128 if you get a number that is zero or larger, then it is a 1. If you get a negative, it is 0, and move on.

#### OutHouse

##### Lifer
here is what i am doing that is wrong.

172-128=44
44-32=12
12-8=4
4-4=0

0

I know the answer is 10101100 but dont know how to get it.

#### dighn

##### Lifer
you need a table of powers of two eg.

exponent number
7 - 128
6 - 64
5 - 32
4 - 16
3 - 8
2 - 4
1 - 2
0 - 1

if you can subtract 128, put a 1 in the 7th place (which is really 8th place if you use 1-based indexing)

for your example, since you can subtract 128, 32, 8 and 4, you put 1's in the 7th, 5th, 3rd and 2nd place. this is of course 0-based indexing, so there's a 0th place as well

eg:

place 76543210
numb 10101100

#### OutHouse

##### Lifer
Originally posted by: TheStu
that could work....

172-128 = 44 so 1
44-64 = -20 so 0
44-32 = 12 so 1
12-16 = -4 so 0
12-8 = 4 so 1
4-4 = 0 so 1
0-2 = -2 so 0
0-1 = -1 so 0
10101100

easy peasy

It just clicked. Thanks!!

#### her209

##### No Lifer
Originally posted by: Citrix
Originally posted by: TheStu
that could work....

172-128 = 44 so 1
44-64 = -20 so 0
44-32 = 12 so 1
12-16 = -4 so 0
12-8 = 4 so 1
4-4 = 0 so 1
0-2 = -2 so 0
0-1 = -1 so 0
10101100

easy peasy
It just clicked. Thanks!!
Bahahaha!

#### neutralizer

##### Lifer
Obligatory: There are 10 kinds of people in this world, ones that understand binary and ones that don't.

##### Senior member
If you just wan to do it, here is another method.

172/2 = 86 rem 0
86/2 = 43 rem 0
43/2 = 21 rem 1
21/2 = 10 rem 1
10/2 = 5 rem 0
5/2 = 2 rem 1
2/2 = 1 rem 0
1/2 = 0 rem 1

so going up: 10101100

Fractions:

.161
.161 x2 = 0.322 so 0
.322 x2 = 0.644 so 0
.644 x2 = 1.288 so 1
.288 x2 = 0.576 so 0
.576 x2 = 1.152 so 1

.00101 with simple truncation.

so 172.161 is 10101100.00101

ok, now do -172.161