# help with binary numbers



## razaron (Jul 2, 2008)

i can do the alphabet in binary but the numbers after ten are confusing me
for example im not sure if, say for instance fifteen would be written as 1111 or 1010 101.


----------



## W1zzard (Jul 2, 2008)

1111 = 8 +4 + 2 + 1

15 is especially easy since it's 16 minus 1 .. 16 is 1000 so one less is 1111 (remove leading 1 and make all other bits 1)


----------



## razaron (Jul 2, 2008)

if 16 is 10000 then i understand 15 being 1111, but what do you mean by
1111 = _8+ 4+ 2 + 1_


----------



## crazy pyro (Jul 2, 2008)

I think that 1111 = 15 because the first one represents 8 and then the second 1 represents half the previous one, my friend was trying to explain it to me but he may have been wrong.


----------



## JoshBrunelle (Jul 2, 2008)

Keep in mind that the numbers are always block of 4. 0000 1111 would be 15, and 0001 0000 would be 16. To represent the alphabet, you would need at least 2 blocks of 4, as there are more than 16 letters (given 0000 stands for something). There are actually 52 characters (2 cases), as well as symbols, so 8 bits are enough to cover them, giving you 255 (256) different combinations. you can't just leave out 0's and still be 100% clear. So 0 would be 0000 0000, and 255 = 1111 1111

0100 0111 
0110 1111 
0110 1111 
0110 0100 
0010 0000 
0100 1100 
0111 0101 
0110 0011 
0110 1011 
0010 0001

Good Luck!

Also, Wizzard was explaining the basics of binary. Each digit represent a power of 2. for example, 
0010 = 2
Quite literally, this means: 
0                 0              1             0              = 2
0*(2^3)  +    0*(2^2) + 1*(2^1) + 0*(2^0)

likewise for 1111 =15
1*(2^3)  +    1*(2^2) + 1*(2^1) + 1*(2^0) = 15
8+4+2+1 = 15

Expand that to 8 places, and you have enough digits to represent the alphabet, and then some.
    1000 1000
= 1*(2^7) + 1*(2^3)
= 128 + 8
= 136


----------



## IggSter (Jul 2, 2008)

16   8   4   2   1 = value for each binary digit
---------------------------------------------
1     0   1   0   0 = 16 + 4 = 20

0     1   1   1   1 = 8 + 4 + 2 + 1 = 15


This is also the best way to think of IP addresses, especially when using/understanding subnet masks eg:

192.168.0.1 (decimal) with the mask 255.255.0.0 (decimal)

192.168.0.1 = 11000000.10101000.00000000.00000001
255.255.0.0 = 11111111.11111111.00000000.00000000

The mask indicates that all bits = 1 are the network address and all set to zero are host addresses.

Network = 192.168.0.0
Hosts = 192.168.0.1 thru 192.168.255.254


----------



## razaron (Jul 2, 2008)

now i get turning binary to decimels like  
0010 1010=0+2+0+8+0+32+0+0
                 =42

0000 1111=1+2+4+8+0+0+0+0
                 =15

but is there no easier way to go from decimel to binary other than working out a big sum


----------



## lemonadesoda (Jul 2, 2008)

15 is 1111 in binary, but is 0001 0101 in BCD (binary coded decimal). BCD takes each digit and codes it separately.  As you can see, it is quicker to convert decimal to BCD and vice versa. You can also do math in BCD on many CPUs.  So BCD is often used by machine code programmers when doing something "quick" without math libraries.

While math in binary is faster and more efficient (bigger numbers in less memory) the problem is translating from binary to decimal and vice versa. Its a PITA to code.

You will find ALL (or nearly all) coin-op arcade games from the 80's and 90's used BCD for their "scores" and "high scores".


----------



## lemonadesoda (Jul 2, 2008)

What is the number 1111 1111?  The answer is -1. If you are working with *signed* 8-bit binary.


----------



## JoshBrunelle (Jul 2, 2008)

lemonadesoda said:


> 15 is 1111 in binary, but is 0001 0101 in BCD (binary coded decimal). BCD takes each digit and codes it separately.  As you can see, it is quicker to convert decimal to BCD and vice versa. You can also do math in BCD on many CPUs.  So BCD is often used by machine code programmers when doing something "quick" without math libraries.
> 
> While math in binary is faster and more efficient (bigger numbers in less memory) the problem is translating from binary to decimal and vice versa. Its a PITA to code.
> 
> You will find ALL (or nearly all) coin-op arcade games from the 80's and 90's used BCD for their "scores" and "high scores".



Indeed using standard binary is a PITA. Had to take an entire course on machine code using an lc3 emulator. We used straight up binary and it was terrible, no idea how I passed the course.


----------



## W1zzard (Jul 2, 2008)

15 divide by 2 = 7 remainder 1
7 divide by 2 = 3 remainder 1
3 divide by 2 = 1 remainder 1
1 divider by 2 = 0 remainder 1

 -----> 1111


----------



## lemonadesoda (Jul 2, 2008)

Please use your "formula" to convert 16.


----------



## W1zzard (Jul 2, 2008)

16 / 2 = 8 0
8 / 2 = 4 0
4 / 2 = 2 0
2 / 2 = 1 0
1 / 2 = 0 1 
--> 10000

Edit: Typo fixed


----------



## IggSter (Jul 2, 2008)

W1zzard said:


> 16 / 2 = 8 0
> 8 / 2 = 4 0
> 4 / 2 = 2 0
> 2 / 2 = 1 0
> ...




10000....fixed your typo


----------



## zaqwsx (Jul 3, 2008)

You can convert from decimal to binary on the pc calculator. Also to convert a # to binary you could do a chart. 

2^8	2^7	2^6	2^5	2^4	2^3	2^2	2^1	2^0
256	128	64	32	16	8	4	2	1
0	0	0	1	1	1	0	0	1


Lets say you want to convert the number 57 to binary. It all becomes addition find the numbers that will add up to 57 and put 1’s and the numbers that don’t work put 0’s. The 0’s on the left after the 1 don’t count so 57 in binary is 111001 or since its blocks of 4 0011 1001.

Look at the image because the numbers didn't come out right.


----------



## Kreij (Jul 3, 2008)

Binary representation of real world objects can be useful at times.

Let's say that you have a beer in front of you that is full (0001) and a twelve pack sitting to your left.
You drink the beer resulting in a binary zero (catastrophe!) so you shift left and grab another resulting in a binary state of 0010.
You know that once you hit 1101 you are out of beer and will have to make a run to the store. This can be prevented by a little forthought at 1010

Pffft ... and people scoff at the usefulness of binary outside of computers.


----------



## lemonadesoda (Jul 3, 2008)

^^ Agree, There are only 10 types of people. Those that know binary, and those that dont.

(OMG thats an old one...)


----------



## W1zzard (Jul 3, 2008)

zaqwsx said:


> You can convert from decimal to binary on the pc calculator. Also to convert a # to binary you could do a chart.
> 
> 2^8	2^7	2^6	2^5	2^4	2^3	2^2	2^1	2^0
> 256	128	64	32	16	8	4	2	1
> ...



yes but thats a lot more complicated than my simple division method


----------



## Deleted member 3 (Jul 3, 2008)

lemonadesoda said:


> ^^ Agree, There are only 10 types of people. Those that know binary, and those that dont.
> 
> (OMG thats an old one...)



Ehm, that's wrong. There are three types of people. People that can count and people that can't count.


----------



## lemonadesoda (Jul 3, 2008)

ROFL. OK

There are 11 types of people.  Those that can count in binary and those that can't.


----------



## zaqwsx (Jul 3, 2008)

razaron said:


> now i get turning binary to decimels like
> 0010 1010=0+2+0+8+0+32+0+0
> =42
> 
> ...



Ya you could use the windows calculator. Go to view then scientific then type in the number you want converted and then go from Dec to Bin. That should be easier if your doing big numbers.


----------



## Kreij (Jul 3, 2008)

Hexidecimal FTW !!

11011110101011011011111011101111 = DEADBEEF

MMmmm... I smell steaks cooking !!!


----------



## Oliver_FF (Jul 3, 2008)

Speaking of Beef, i've got some serious qualms with whichever idiot coined the term "two's compliment" to read out a negative binary number...

You know, where you "invert all the bits and add 1" or whatever?

Well, instead of cacking around with that why not press the minus button on your calculator first?? idiot to the person that coined that term. At uni whenever negative numbers come up everyone starts talking about this two's compliment and I just feel like slapping them silly...

1100 1100 as a signed integer is number (-52):

Well, for the 'educated' your supposed to invert all the bits and add 1 to discover that:
0011 0011(inverted)
0011 0100(add the 1)
add that up, 32+16+4 = 52; then stick the minus sign in front of it...

Much simpler:
(-128)+64+8+4 = (-52)

[end-rant]


----------



## lemonadesoda (Jul 3, 2008)

Oliver, you need to think about how this is done in machine code.  You have instructions on a CPU that handle binary arithmetic. You cant do "blackboard math" on a CPU. If you are interested go here:

http://6502org.wikidot.com/software-math
http://codebase64.org/doku.php?id=base:6502_6510_maths
http://forum.6502.org/viewtopic.php?p=6338&sid=5cffd0599b1bce4d5fb06420d4b27203
http://www.atarimax.com/freenet/fre.../7.TechnicalResourceCenter/showarticle.php?14

(I'm giving you links to 6502 code because that was one of the top 8-bit processors from the 70's and 80's ... and the foundation of college machine code math)

Until you see it in practice, it is conceptually difficult to know why it is done like this. You cant imagine how tough it was to program back then without compilers, IDEs, and math libraries that are standard today.


----------

