Sie sind auf Seite 1von 9

Binary Digits

Binary Numbers
A Binary Number is made up of only 0s and 1s.
So each digit has only two possibilities: 0 or 1

Bits
In the computer world "binary digit" is often shortened to the word "bit"

More Than One Digit


So, if one digit has only two possible "positions" (like "0" and "1", or
"On" and "Off"), how many positions are there with 2 or more binary
digits?
For example, how many different ways could 4 digits be set (such as in
our 4 different drums example)?
Let's write them all down, starting with 1 digit (you can test it yourself
using the switches):
One digit will have 2
positions...
...two digits have 4
positions...

0
1
0
1

...three digits have 8


positions...

0
1
0
1
0
1

0
1

0
1
0
1
0
1
0
1

00
01
10
11
000
001
010
011
100
101
110
111

... and four digits have


16 positions.

0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

1
1

0
1

0
1

0
1

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

And, in fact, we have created the first 16 binary numbers:


Decimal:
Binary:

0 1 2 3
0

10

11

100 101 110 111 1000

9
1001

10 11 12 13 14

15

1010

1111

1011

1100

1101

1110

This is quite a useful thing to remember. If you forget how the sequence
of binary numbers go, just think:
"0" and "1" {0,1}
then "0" and "1" again but with a "1" in front: {0,1,10,11}
then take those four with "1"s as a third digit:

{0,1,10,11,100,101,110,111}
and so on!
Or just count exactly like decimal numbers, but don't use 2,3,4,5,6,7,8
or 9.

Binary Digits ... They Double!


Also notice that each time you add another binary digit you double the
possibilities. Why double? Because you have to take all the previous
possible positions and match them with a "0" and a "1" like above.
So, if you had 5 things, then the total would be 32, 6 things would be
64, etc.

Using exponents, this can be shown as:


No of Digits
1
2
3
4
5
6
etc...

Formula
21
22
23
24
25
26
etc...

Settings
2
4
8
16
32
64
etc...

Example: when you have 50 binary digits (or even 50 things that can
only have two positions each), how many different ways is that?
Answer 250 = 2 2 2 2 ... (fifty of these) = 1,125,899,906,842,624
So, a binary number with 50 digits could have 1,125,899,906,842,624
different values.
Or to put it another way, it could show a number up to
1,125,899,906,842,623 (note: this is one less than the total number of
values, because one of the values is 0).

Hexadecimal
Lastly, I would like to tell you about the special relationship between
Binary and Hexadecimal.
There are 16 Hexadecimal digits, and we already know that 4 binary
digits have 16 possible values. Well, this is exactly how they relate to
each other:
Binary:

10

11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111

Hexa- 0
decimal
:

So, when people use computers (which prefer binary numbers), it is a lot
easier to use the single hexadecimal digit rather than 4 binary digits.
For example, the binary number "100110110100" is "9B4" in
hexadecimal. I know which I would prefer to write!

Decimal vs Binary
Here are some equivalent values:
Decima 0
l:

Binary:

10

11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110

10 11

12 13

14

15

1111

Here are some larger equivalent values:


Decimal:

20

25

30

40

50

100

200

500

Binary:

10100

11001

11110

101000

110010

1100100

11001000

111110100

"Binary is as easy as 1, 10, 11."


Position
In the Decimal System there are the Units, Tens, Hundreds, etc
In Binary, there are Units, Twos, Fours, etc, like this:

This is 18 + 14 + 02 + 1 + 1(1/2) + 0(1/4) +


1(1/8)
= 13.625 in Decimal
Numbers can be placed to the left or right of the point, to indicate values
greater than one or less than one.

10.1

The number to the left of the point is a whole number


(10 for example)

As we move further left, every number place


gets 2 times bigger.
The first digit on the right means halves (1/2).

As we move further right, every number place


gets 2 times smaller (half as big).

Example: 10.1
The "10" means 2 in decimal,
The ".1" means half,
So "10.1" in binary is 2.5 in decimal

Binary to Decimal to Hexadecimal Converter.

1234 = ((1*10^3)+(2*10^2)+(3*10^1)+(4*10^0))
Lets start with what a binary number looks like:
01001010
2 to the power of 0 = 1 (2^0)
2 to the power of 1 = 2 (2^1)
2 to the power of 2 = 4 (2^2) or (2*2)
2 to the power of 3 = 8 (2^3) or (2*2*2)
2 to the power of 4 = 16 (2^4) or (etc.)

2 to the power of 5 = 32 (2^5)


2 to the power of 6 = 64 (2^6)
2 to the power of 7 = 128 (2^7)
2 to the power of 8 = 256 (2^8)

2 to the power of x = (2^x)


Ok, lets apply this chart to the binary number I gave a few moments ago to
get us the decimal equivalent. All digits that are 0 remain 0, and are only
useful as position placeholders. All digits that are assigned a value of 1 have
a decimal value that is equal to the power (2^x) of their position within the
chart.
128 64 32 16 8

01001010 = 64 + 8 + 2
which means that 01001010 = 74
Successive subtraction:

Now lets do the inverse. To convert 74 to binary, youll have to start by finding
the biggest power of 2 that is valued less then 74. Finding this number is
important because it will determine the positive value at the left of your binary
number. In this case, it is 64.
Lets put a 1 in the 2^6 (2*2*2*2*2*2 = 64) position.
01000000
After, take your initial decimal number, and subtract it by the value you just
found out. 74 64 = 10. Now, lets do the same procedure as before. What is
the biggest power of 2 that is valued less then 10? It is 8.
Put a 1 in the 2^3 position ( 2*2*2 = 8 )
and continue doing this until the total equals your initial decimal number.
01001010
Even numbers always finish with a 0 and odd ones end in 1. This is because
the rightmost digit in a binary number can only have a decimal value of 0 or 1.
Successive Devision:
Another way to convert from decimal to binary is by successive divisions.

74 / 2 = 37
37 / 2 = 18
18 / 2 = 9
9 /2= 4
4 /2= 2
2 /2= 1

Remainder
0
1
0
1
0
0

1 /2= 0

(74)10 = (1001010)2
(1001010)2 = 0x20+1x21+0x22+1x23+0x24+0x25+1x26
= 2 + 8 + 64 = (74)10
Binary addition
works in the same way as the decimal system, except that only 0's and 1's can
be used, instead of the whole spectrum of 0-9. This actually makes binary
addition much simpler than decimal addition, as we only need to remember the
following:
0+0=0
0+1=1
1+0=1
1 + 1 = 10
As an example of binary addition we have,
101
+101
a) To add these two numbers, we first consider the "ones" column and
calculate 1 + 1, which (in binary) results in 10. We "carry" the 1 to the "2s"
column, and the leave the 0 in the "ones" column.
b) Moving on to the "2s" column, we calculate 1 + (0 + 0), which gives 1.
Nothing "carries" to the "4s" column, and we leave the 1 in the "2s" column.
c) Moving on to the "4s" column, we calculate 1 + 1, which gives 10. We
"carry" the 1 to the "8s" column, leaving the 0 in the "4s" column.
101
+101
1010
Another example of binary addition:
1011
+1011
10110
Note that in the "2s" column, we have 1 + (1 + 1), where the first 1 is
"carried" from the "ones" column. Recall that in binary,
1 + 1 + 1 = 10 + 1
= 11

Character to Binary Convertion

upposeyou'reeditingatextfilewithatexteditor.Becauseyou'reusinga
texteditor,you'reprettymucheditinganASCIIfile.Inthisbrandnewfile,
youtypein"cat".Thatis,theletters'c',then'a',then't'.Then,yousavethe
fileandquit.

Whathappens?Forthetimebeing,wewon'tworryaboutthemechanism
ofwhatitmeanstoopenafile,modifyit,andcloseit.Instead,we're
concernedwiththeASCIIencoding.
IfyoulookupanASCIItable,youwilldiscovertheASCIIcodefor0x63,
0x61,0x74(the0xmerelyindicatesthevaluesareinhexadecimal,instead
ofdecimal/base10).
Here'showitlooks:
ASCII
c'
a'
t'
Hex

63

61

74

Binary 01100011
01100001
01111000
EachtimeyoutypeinanASCIIcharacterandsaveit,anentirebyteis
writtenwhichcorrespondstothatcharacter.Thisincludespunctuations,
spaces,andsoforth.Irecallonetimeastudenthasused100asterisksin
hiscomments,andtheseasterisksappearedeverywhere.Eachasteriskused
uponebyteonthefile.Wesavedthousandsofbytesfromhisfilesby
removingcomments,mostlytheasterisks,whichmadethefilelooknice,
butdidn'taddtotheclarity.
Thus,whenyoutypea'c',it'sbeingsavedas01100011toafile.
When arranged in sets of 8 bits (1 byte) 256 values can be represented (0-255).
Using an ASCII chart, these values can be mapped to characters and text can be
stored.

ASCII = American Standard Code for Information


Interchange
Now that you ASCII, its ANSI

ASCII (see definition above) is old fashioned. It refers to a


coding scheme of 7 bits used in old computers before the
advent of the IBM System 360 in the early 1960's. With
the S/360, IBM introduced a revised coding scheme called
EBCDIIC (see below) that uses 8 bits.
H.W.: Find and print the ASCII table?