Decimal Representation of Numbers

Binary Representation of Numbers

Binary Arithmetic

An Addition Circuit

Two's Complement

Using Two's Complement to Perform Subtraction

Hexadecimal Notation


Decimal Representation of Numbers

Usually, we use decimal numbers in our normal life. Decimal (or base 10) notation expresses a number as a string of digits in which each digit's position indicates the power of 10 by which it is multiplied. The right-most position is the one's place (or 100 place), to the left of that is the ten's place (or 101 place), to the left of that is the hundred's place (or 102 place), and so forth.

For example, 3,096 has a 3 in the thousand's place, a 0 in the hundred's place, a 9 in the ten's place, and a 6 in the one's place.

In exponential notation, this equation can be rewritten as

More generally, we can say that decimal notation is based on the fact that any positive integer can be written uniquely as a sum of products of the form

d * (10n)

where each n is a nonnegative integer and each d is one of the decimal digits 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9.






Binary Representation of Numbers

For modern electronics, binary notation is used. In binary notation (or base 2 notation), any integer can be represented uniquely as a sum of powers of the form

d * (2n)

where each n is an integer and each d is one of the binary digits (or bits) 0 or 1. For instance,

Therefore, the decimal number 19 (or 1910) can be represented in binary number as 10011 (or 100112). The places in binary notation correspond to the various powers of two. The right-most position is the one's place (20), to the left of that is the two's place (21), to the left of that is the four's place (22), and so forth. The table of powers of 2 which corresponds to the decimal form is:

  power of 2     210     29     28     27     26     25     24     23     22     21     20  
  decimal form     1,024     512     256     128     64     32     16     8     4     2     1  










Binary Arithmetic

The process of adding and subtracting binary arithmetic is similar to that of decimal arithmetic. In binary arithmetic the number 2 plays a role similar to that of the number 10 in decimal arithmetic. Consider: when adding numbers in decimal, any sum over 9 in any decimal column means you must carry over to the next place.

  8
+7
15

The same is true for binary addition - when the sum of two numbers exceeds 1, you must carry over into the next column. For instance, the following addition is performed for 7 + 9.

Decimal Binary
 1
   9
+  7
  16
111
 1001
+ 111
10000

carry row


Likewise, when subtracting 2 numbers, it is sometimes necessary to "borrow" from the column to the left. To illustrate this, we will subtract 3 from 21.

Decimal Binary
  1 10
  21
-  3
  18
 0 2
10101
- 011
10010

borrow row


As can be seen in the decimal subtraction, a 10 is borrowed from the 101 column and added to the 1 in the 100 column; instead of 1 - 3, you now have 11 - 3. The same thing happens in the binary subtraction. A 2 is borrowed from the 22 column and added to the 21 column; 0 - 1 becomes 2 - 1.









An Addition Circuit

To add two binary digits X and Y in a circuit, we use a half adder to handle the sum digit and the carry bit. The half adder is not a gate, because it has two outputs while a gate can have only one.

  X     Y    X Y X Y (XY)(X Y)

1

1

1

1

0

1

0

1

0

1

0

1

1

0

1

0

0

0

0

0

X Y produces the carry bit, while (XY)(X Y) is the logic needed for the sum bit.

To add two multidigit binary numbers, we have to use a full adder which allows adding three digits at the same time.







Two's Complement

Given a positive integer m, the two's complement of m relative to a fixed bit length n is the n-bit binary representation of 2n - m.  In other words, the two's complement representation is a way of representing a negative number. For instance, to find the 8 bit two's complement of 35, we have (28 - 35)10 = (256 -35)10 = 22110 = (128 + 64 + 16 + 8 + 4 + 1)10 = 110111012

In general, the 8-bit two's complement of a positive integer m that is at most 255 can be computed by the following steps:

1. Write the 8-bit binary representation of m.
(For this example, let m = 7.)
00000111
2. Switch all the 1's to 0's and 0's to 1's. 11111000
3. Add 1 in binary notation. The resulting binary number is the two's complement representation for -7. 11111001

Conversely, we can find a the decimal value of a 2's complement binary number using the following steps:

1. Write the 8-bit binary 2's complement number. 11110101
2. Switch all the 1's to 0's and 0's to 1's. 00001010
3. Add 1 in binary notation. Translate the resulting binary number into decimal, and take the negative. In this case, the result is -11. 00001011









Using Two's Complement to Perform Subtraction

Two's complement representation is primarily useful when performing binary subtraction. Instead of subtracting a binary number m from another binary number n, you can add the two's complement of m to n to obtain the correct result.

It is important to realize that, when using 2's complement, the leftmost bit becomes a sign bit. A 0 in the leftmost position means the number is positive, and a 1 in the leftmost position means the number is in 2's complement form and is negative. Therefore, adding 2 numbers (negative or positive) within a certain range means that you must have enough digits to represent your numbers, plus 1 extra bit in which to store the sign.   i.e., if you wish to subtract 7 from 13, you need at least 4 bits to represent 13 (since 13 is greater than 23 but less than 24), plus one extra bit for the sign.

For example, to perform the subtraction 13 - 7:

1. Convert both integers to binary.  Remember to add an extra bit to hold the sign.   (13 = 1101, then add 1 bit to get 01101.) Both numbers need to be represented with the same number of bits. 13 = 01101
 7 = 00111
2. Convert the number to be subtracted to 2's complement form. 0011111001
3. Add the resulting binary numbers using ordinary binary addition.     01101
 +11001
 100110
4. Truncate any leading 1 (overflow) that occurs.  (In this case, a 1 has overflowed into the 25th position.) 10011000110
5. Convert the result back to decimal form. If the leftmost position is a 0, the number is positive. If the leftmost position is a 1, the number is in 2's complement form; convert the number back by taking the 2's complement of it, then convert to decimal and take the negative. 00110 = 6










Hexadecimal Notation

Hexadecimal or base 16 notation is based on the fact that any integer can be expressed as a sum of numbers of the form,

d * (16n)

where each n is a nonnegative integer and each d is one of the integers from 0 to 15. The following table lists the first 16 numbers in the decimal, hexadecimal, and 4-bit binary systems.

Decimal Hexadecimal 4-Bit Binary

0

0

0000

1

1

0001

2

2

0010

3

3

0011

4

4

0100

5

5

0101

6

6

0110

7

7

0111

8

8

1000

9

9

1001

10

A

1010

11

B

1011

12

C

1100

13

D

1101

14

E

1110

15

F

1111


To convert an integer from hexadecimal to binary notation:

1. Write each hexadecimal digit of the integer in fixed 4-bit binary notation.  For example, to convert AE9: A = 1010
E = 1110
9 = 1001
2. Juxtapose the results. AE9 = 1010 1110 1001

Conversely, to convert an integer from binary to hexadecimal notation:

1. Starting from the right, group the digits of the binary number into sets of four, and adding leading zeros as needed to complete the leftmost group of four. 101011  0010 1011
2. Convert the binary numbers in each set of four into hexadecimal digits. 0010 = 2
1011 = B
3. Juxtapose the hexadecimal digits. 00101011 = 2B









Go to next section review.
Go to Class Agenda.