Home / converting a number to binary / Counting in base 10, 2 and 16 1. Binary Numbers - UC Davis

# Counting in base 10, 2 and 16 1. Binary Numbers - UC Davis - converting a number to binary

Counting in base 10, 2 and 16
1. Binary Numbers
A super-important fact:
(Nearly all) Computers store all information in the form of binary numbers. Numbers,
characters, images, music files --- all of these are stored in a computer using binary numbers.
But ... how? Well, before we get to that, let's study the binary number system.
A binary number is a string of 0's and 1's.
What is the meaning of a binary number?
Let us look at the decimal system first. Consider the number 5281
? There is one "position" or "place" for each power of 10
? The "1" is in the 1's place
? The "8" is in the 10's place
? The "2" is in the 100's place
? The "5" is in the 1000's place
So we have: 5281 = 5 * 1000 + 2 * 100 + 8 * 10 + 1 * 1
Now let's move to the binary number system. Consider this number: 110101. There is a separate
"place" for each power of 2. Starting at the right, we have:
? a 1 in the 20=1's place
? a 0 in the 21=2's place
? a 1 in the 22=4's place
? a 0 in the 23=8's place
? a 1 in the 24=16's place
? a 1 in the 25=32's place
So we have: 110101=1*32 + 1*16 + 0*8 + 1*4 + 0*2 + 1 = 53
In other words: 110101 in binary is equivalent to 53 in our usual decimal system of numbers.
A few more examples:
? 1 1 1 1 = 1*8 + 1*4 +1*2 +1*1 = 15
? 0 1 0 1 = 0*8 + 1*4 + 0*2 + 1*1 = 5
? 1 0 1 1 1 = 1*16 + 0*8 + 1*4 + 1*2 + 1*1 = 23
? 1 1 = 1*2 + 1 = 3
? 1 1 1 0 = 1*8+ 1*4 + 1*2 = 14
Some Terminology:
? Each digit of a binary number (each 1 or 0) is called a bit.
? 1 byte = 8 bits.
? 1 KB = 1 kilobyte = 2^10 bytes = 1024 bytes (approx 1 thousand bytes).
? 1 MB = 1 Megabtye = 2^20 bytes = 1,048,580 bytes (approx 1 million bytes).
? 1 GB = 1 Gigabyte = 2^30 bytes = 1,073,741,824 bytes (approx 1 billion bytes)
Converting decimal to binary:
To convert a decimal number to binary, keep dividing the number by 2 until you get down to 0.
Keep track of the remainders.
Example: Consider the decimal number 57.
? 57 divided by 2 = 28 Remainder 1
? 28 divided by 2 = 14 Remainder 0
? 14 divided by 2 = 7 Remainder 0
? 7 divided by 2 = 3 Remainder 1
? 3 divided by 2 = 1 Remainder 1
? 1 divided by 2 = 0 Remainder 1
Now list the remainder values from bottom to top: 111001: this is the binary form of 57.
Let us check our answer (111001) by converting it back to decimal:
111001 = 32 + 16 + 8 + 1 = 57, so we are correct.
Maximum Value of a binary number:
Consider a binary number with N bits (where N is a number).
Its maximum possible value is 2N - 1 (2 to the power of N, minus 1)
Example:
let N = 3, for a 3-bit binary number, the maximum value is 111, i.e. 23-1=7
2. Counting Using Binary Numbers
Consider how counting works in the decimal system. We start with 1 digit. We count using the
numerals 0 through 9. After we reach 9, we've run out of numerals. So, we have to add a second
digit. We start that digit at 1. Then we cycle the first digit through the numerals 0 through 9
again, to create the numbers 10-19. After we reach 19, we've run out of numerals in the "1's
place" again, so we increment the second digit to 2. Eventually, we reach 99. We've run out of
numerals in the "1's" place, so we want to increment the second digit again. But, now we've run
out of numerals for the second digit as well. So, we have to introduce a 3rd digit, and we start it
at 1. And so on.
Counting using binary numbers works the same way, except that we only have 2 numerals (1 and
0) for each digit. So, we start with 1 digit. We count using the numerals 0 through 1:
0
1
We are already out of numerals. So, we have to add a second digit. We start that digit at 1, and
then we can cycle the first digit through the numerals 0 through 1 again:
10
11
Next we add a 3rd digit, and start it at 1. Now we can cycle the 1st and 2nd digits as we did
before:
100
101
110
111
And so on. Starting from the beginning again, the sequence of binary numbers looks like this:
0
1
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1111
10000
...
Let us rewrite this sequence, with the decimal value of each number listed to the right:
binary decimal
------ -------
0 0
1 1
10 2
11 3
100 4
101 5
110 6
111 7
1000 8
1001 9
1010 10

How to convert real number to binary format? Binary equivalent of a real number 1. Convert the integer part by repeated division by 2 (or some other algorithm) 2. Convert the fraction part by repeated multiplication by 2 3. Join these two parts together to form a binary fixed point number 4. Add a zero exponent to get the number into binary floating point form 5.

#### Pdf INFO

Title: Microsoft Word - Counting.doc
Author: Patrice Koehl
Creator: Word
Producer: Mac OS X 10.4.11 Quartz PDFContext
CreationDate: Thu Dec 31 10:23:33 2009
ModDate: Thu Dec 31 10:23:33 2009
Tagged: no
Form: none
Pages: 8
Encrypted: no
Page size: 612 x 792 pts (letter) (rotated 0 degrees)
File size: 142533 bytes
Optimized: no