To Documents

Positional Number Systems Tutorial

 

Primary reference: Wikipedia
http://en.wikipedia.org/wiki/Category:Positional_numeral_systems

 

A. Positional Number Systems

Since the beginning of elementary school, children use the decimal number system. We learn that the number 365 represents 3 hundreds, 6 tens and 5 ones. Formally, this is written as 365 = 3 × 102 + 6 × 101 + 3 × 100. The meaning of each digit is determined by counting from the right: 5 on the right represents the ones (100) place. Next, 6 represents the tens (101) place and 3 represents the hundreds (100) place. The meaning of the digits in larger numbers is determined by this Powers of Ten Table.

The decimal system is one of many positional number systems that have been used historically. Actually any integer greater than one can be used as the base of a positional number system. For example, 124 in base 7 represents

in base 10. A shorter notation for this is 1247 = 6710. A base-n positional number system requires n digits: base-10 requires the ten digits

Base-7 requires the seven digits When the base is greater than 10, more than ten digits are required, so digits must be invented. Here are the digits for base 12:

X denotes 10; E denotes 11. Here are the digits for base 16:

0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F

A through F represent 10 through 15, respectively.

Not all number systems are useful, however. Here are some of the most important positional number systems, both historically and in current technology:

Practice Problems

  1. Convert the following numbers of various bases into decimal:

  2. Why is each of these numbers are illegal?

 

B. Unsigned Binary Numbers

Binary numbers are used to represent integer data in modern digital computers This section describes how to use binary numbers to represent nonnegative integers. In section C, we will see how negative integers are represented in computer data. Use the following Powers of Two Table. A bit is defined as one binary digit. One byte is defined as eight bits.

Example: Convert the one byte unsigned binary number 011011012 to decimal:
011011012 = 0 × 27 + 1 × 26 + 1 × 25 + 0 × 24 + 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 64 + 32 + 16 + 8 + 4 + 1 = 123.

This calcutation can be shortened to 011011012 = 64 + 32 + 16 + 8 + 4 + 1 = 123.

Example: Convert 5910 to unsigned one byte binary.
Repeatedly subtract the largest power of two that is less than or equal to the number remaining. Stop when you reach 0:
59 - 32 = 27; 27 - 16 = 11; 11 - 8 = 3; 3 - 2 = 1; 1 - 1 = 0.
Thus 59 = 32 + 16 + 8 + 2 + 1 = 001110112.

Practice Problems

  1. Convert these numbers to decimal:

  2. Convert these numbers to unsigned one-byte binary.

 

C. Binary Addition

Binary addition uses these arithmetic facts:

If the an addition gives a two bit result, the leftmost bit is carried to the left in the same way that a digit is carried in decimal addition.

Example: Perform the binary addition 001110012 + 001010112. Start from the right and obtain the following:

Carry 0 1 1 1 0 1 1 0
Value 1 0 0 1 1 1 0 0 1
Value 2 0 0 1 0 1 0 1 1
Result 0 1 1 0 0 1 0 0

Practice Problems

  1. Perform these binary additions:

 

D. Converting Between Binary and Hex

Converting between binary and hex (base 16) is especially easy because each group of four binary bits correspond to one hex digit. Here is the Hex Digits in hex, binary and decimal.

Example: Convert the hex number 2AE916 to binary. Look up each hex digit in the hex digits table to give 2 --> 0010; A --> 1010; E --> 1110; 9 --> 1001. Putting them together gives 00101010111010012.

Example: Convert the binary number 101110102 into hex. Look up each group of four digits in the hex digits table to give 1011 --> B; 1010 --> C. Putting these together gives BC16.

 

E. Signed Binary Numbers

The unsigned binary representation can only be used for nonnegative integers. For negative integers, signed integers are needed. For signed integers, a binary number with its leftmost bit set to 0 represents a positive integer or zero. A binary number with its leftmost bit set to 1 represents a negative integer. Here are the meanings of the Meanings of Signed and Unsigned Integers. Note that half of the signed integers (from 00000000 to 01111111) are positive and the other half (from 11111111 to 10000000) are negative.

Signed integers work somewhat like the odometer of an car that runs backwards if the car travels in reverse. If a car with a decimal odometer starts at 000000 and backs one mile out of the dealership parking lot, the odometer will show 999999; the signed representation of -1 is 999999. Similary, if a car with a binary odometer starts at 00000000 and backs one mile out of the lot, the odometer will show 11111111; the signed one-byte representation of -1 is 11111111. Backing one more mile out of the parking lot causes the binary odometer to show 11111110, so the signed representation of -2 is 11111110. (Look again at the table comparing the signed and unsigned integers.)

Algorithm for Negating a Binary Number

  1. Complement each bit of the binary number (change 0 to 1 and 1 to 0).

  2. Searching from the right, find the first 0 at position p.

  3. Change that bit (at position p) to 1.

  4. Change each bit to the right of position p to 0.

Example: Compute the signed representation of -45.

  1. 45 in binary is 32 + 8 + 4 + 1 = 001011012.

  2. The bitwise complement of 001011012 is 110100102.

  3. The first 0, searching from the right, is at position 8.

  4. Change the 0 at position 8 to 1 to obtain 110100112.

  5. There are no more bits to the right to change to 1.

Example: Compute the signed representation of -96.

  1. 96 in binary is 64 + 32 = 011000002.

  2. The bitwise complement of 011000002 is 100111112.

  3. The first 0, searching from the right, is at position 3.

  4. Change the 0 at position 8 to 1 to obtain 101111112.

  5. Change the 1 bits to the right of position 3 to 0: 101000002.

Practice Problems

  1. Convert to one-byte signed binary:

      -3,   -6,   -9

  2. Convert to decimal:

      111111002,    111110012,    111101112

 

F. Maximum and Minimum Values

Practice Problems

  1. What is the largest possible unsigned one-byte binary number?

  2. What is the largest possible unsigned two-byte binary number?

  3. What is the largest possible unsigned four-byte binary number?

  4. What is the largest possible signed one-byte binary number?

  5. What is the largest possible signed two-byte binary number?

  6. What is the largest possible signed four-byte binary number?

 

F. Binary Character Encoding Systems

Although representing integers in binary is very important, computers must also deal with nonnumeric information like characters. ASCII (American System for Computer Information Interchange) binary codes are used for storing and transmitting character information. This system is capable is encoding all of the characters on a standard American computer keyboard.

These two tables show the standard ASCII codes:

  1. ASCII Codes for Printable Characters

  2. ASCII Codes for Nonprintable Characters

Example: Character to Binary ASCII

To convert the characters "!%TUNA9*>~" to binary ASCII, first convert the characters to hex ASCII by looking them up in the ASCII Table for Printable Characters. The following codes are obtained:

21 25 54 55 4E 41 39 2A 3C 7E

Translate each character to binary with the Hex Digits Table.

00100001 00100101 01011000 01010101 01001110 01000001 00111001 00101010 00111100 01111110

Example: Binary ASCII to Character

To convert the binary ASCII codes 00110010 00111010 00110011 00110000 to characters, first translate to hex (four bits per hex digit): 32 3A 33 30. Now look up these codes in the ASCII Table for Printable Characters to obtain "2:30"

Although ASCII is strictly designed for encoding American English characters, computers routinely encode characters from every major language (ancient and modern) in the world. The best system to use for encoding characters for languages other than English is the Unicode system. For more details, see the Unicode website www.unicode.org website.

Practice Problems

  1. Convert this phrase into binary ASCII codes:

  2. Convert these binary ASCII codes into characters: