• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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.
 
that could work....

for your example...

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
 
Originally posted by: TheStu
that could work....

for your example...

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.

 
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.
 
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.
 
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
 
Originally posted by: TheStu
that could work....

for your example...

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!!

 
Originally posted by: Citrix
Originally posted by: TheStu
that could work....

for your example...

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!
 
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 😉
 
Back
Top