Review and Exercises for Base 2


Base 2 numbers compared to Base 10 numbers.

Numbers in base 2 use only the digits 0 and 1 just as numbers in base 10 use only the digits 0, 1, ..., 9. Base 2 digits are called bits (short for binary digit).

Numbers in base 10 are evaluated by considering the place value of each digit.

So, for example, the value of number 237 is 7 ones plus 3 tens plus 2 hundreds.

Note that each place value is a power of 10. The rightmost place value is 100=1, the next is 101 = 10, the next is 102 = 100 and so on.

The same is true for numbers in base 2. I.e., Numbers in base 2 are evaluated by considering the place value of each digit. However, the place values are powers of 2, not powers of 10.

So, the rightmost place value is 20=1, the next place value is 21=2, the next is 22=4 and so on.

The rightmost place or position in a number is designated the 0 position. The next postion to the left is designated the 1 position and so on.

Computers operate internally using Base 2 numbers in groups of 8 bits called bytes. Let's convert some 8 bit bytes into base 10 numbers.
00100101. The preceding byte contains ones in the 0 position, the 2 position and the 5 position. Therefore the value of the base 2 number 00100101 when converted to base 10 is 20 + 22 + 25 = 1 + 4 + 32 = 37.

More examples of base 2 numbers.
00000011 = 2 + 1 = 3
01000101 = 64 + 4 + 1 = 69
01111111 = 64 + 32 + 16 + 8 + 4 + 2 + 1 = 127

Base 16

To be more efficient, computers often compute with groups of bytes. A group of 4 bytes has 32 bits and a group of 8 bytes has 64 bits.
It is inconvenient for computer programmers and designers to have to write down large numbers of bits. To make this task easier programmers and designers often use base 16 rather than base 2.

Base 16 is often called hexadecimal or hex for short.

Base 16 uses 16 digits. They are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F.
The base 16 digits A, B, C, D, E and F have the base 10 values 10, 11, 12, 13, 14 and 15.

The place values for base 16 are powers of 16. So the 0 position has value 160=1, the 1 position has value 161=16, the 2 postion has value 162=256 and so on.

Any base 16 digit may be represented using 4 bits. A group of 4 bits is called a nibble.
Therefore any byte (8 bits) may be represented using only 2 hex digits.
For example, 3A = 0011 1010 and EF = 1110 1111

Representing Negative Numbers

Negative numbers may be represented in base 2 using two's complement.
In two's complement the place values for positions 0 through 6 are exactly as they are for ordinary positive base 2 numbers. However the last position of the byte, position 7, has value -27 = -128 rather than a positive 128.

Examples of negative base 2 numbers in two's complement.

10000001 = -128 + 1 = -127
10001010 = -128 + 8 + 2 = =118
11111111 = -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1

ASCII - American Standard Code for Information Interchange

ASCII is a means of encoding characters (letters and other symbols such as comma, dollar sign, etc.) as numbers.
ASCII codes only require 7 bits (values 0 - 127) but since computers use data in chunks of bytes one complete byte is normally used for each ASCII code.
The most common ASCII codes are the following:
space = 32
uppercase letters (A - Z) = 65 - 90
lowercase letters (a - z) = 97 - 122
digits (0 - 9) = 48 - 57


More Base 2 information including floating point representation.


Exercises

Convert the following numbers as indicated.

Base 2 to Base 10
1011
1001001
1100111

Base 10 to Base 2
37
217
3189

Base 16 to Base 10
32
AF
11F

Perform the following operations as indicated in base 2.

1101 + 111 =                       1001 + 1010 =

1001 - 111 =                       1000 - 101 =

  1011                             1101
*  101                            * 111
-------                            -----


  101/11 =                       11/101 = 
You may create your own additional exercises and easily check your answers by converting your numbers to base 10, performing the operation and converting the answer back to base 2.




Top of this page   Top of page      Home page   Home page