Binary

Topics Discussed:

  1. What is Binary?
  2. Converting Binary and Decimal
  3. Adding in Binary
  4. Bits, Bytes, Words, Longs

1. Binary numbers and arithmetic let you represent any amount you want using just two digits: 0 and 1.

2. Here are some examples:

Decimal 1 is binary 0001
Decimal 3 is binary 0011
Decimal 6 is binary 0110
Decimal 9 is binary 1001

Each digit “1″ in a binary number represents a power of two, and each “0″ represents zero:

0001 is 2 to the zero power, or 1
0010 is 2 to the 1st power, or 2
0100 is 2 to the 2nd power, or 4
1000 is 2 to the 3rd power, or 8.

When you see a number like “0101″ you can figure out what it means by adding the powers of 2:

0101 = 0 + 4 + 0 + 1 = 5
1010 = 8 + 0 + 2 + 0 = 10
0111 = 0 + 4 + 2 + 1 = 7
Addition

3. Adding two binary numbers together is like adding decimal numbers, except 1 + 1 = 10 (in binary, that is), so you have to carry the one to the next column:

0001
+0100
—-
0101 (no carries to get this)

0001
+0001
—-
0010 (1 plus 1 is 10, carry the 1 to the next column)

0011
+0011
—-
0110 (1 + 1 = 10, so carry; then 1 + 1 + 1 = 11, so carry again)

0011
+0101
—-
1000 (carry in every column here)

Subtraction is harder. Don’t worry about it.
Larger Numbers

Here are the numbers from 0 to 15, in binary:

(The leading zero’s can actually be removed, the critical values start at the first “1″ from left to right.)

0000 = 0
0001 = 1
0010 = 2
0011 = 3
0100 = 4
0101 = 5
0110 = 6
0111 = 7
1000 = 8
1001 = 9
1010 = 10
1011 = 11
1100 = 12
1101 = 13
1110 = 14
1111 = 15
10000 = 16
10001 = 17
10010 = 18
(etc.)

4. Bits, Bytes, Words, Longs

Each “1″ or “0″ is considered an individual “bit”
“byte” = 8 bits
“word” = 16 bits
“long” = 32 bits
“kilobyte” = 1024 bytes (1024 is 2 to the 10th power)
megabyte ~ million bytes

This is why there is a numerical limit to the size of the variables on the Propeller chip. The numbers are limited to the amount of RAM (Random Access Memory) used.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>