OOPortal OOPortal


Data Types  «Prev 

Negative Integers Representation

At this point you are probably wondering why negative integers are represented in this strange fashion. The simple answer is that it makes arithmetic with signed integers easy for the computer to perform. This is best illustrated with a simple example. Consider the sum of the integers 12 and -3.
To perform this addition, the computer would simply add the digits in the corresponding positions of the two 8-bit binary numbers, as shown below.

00001100
11111101
========
00001001

In each column of the sum, when two 1s are added together the sum is 0 with a carry of 1, and when three 1s are added together the sum is 1 with a carry of 1. The carry after adding the digits in the leftmost position is discarded. The sum of the two numbers is 00001000. As expected, this is the 8-bit binary representation of the decimal number 9.

Radix number systems

An ordinary decimal number with which everyone is familiar consists of a string of decimal digits and, possibly, a decimal point. The general form and its usual interpretation are shown in Figure 3-5.1. The choice of 10 as the base for exponentiation, called the radix, is made because we are using decimal, or base 10, numbers. When dealing with computers, it is frequently convenient to use radices other than 10. The most important radices are 2, 8, and 16. The number systems based on these radices are called binary, octal, and hexadecimal, respectively.

Figure 3-5.1 : The general form of a decimal number.

A radix k number system requires k different symbols to represent the digits 0 to k − 1. Decimal numbers are built up from the 10 decimal digits
0 1 2 3 4 5 6 7 8 9

In contrast, binary numbers do not use these ten digits. They are all constructed exclusively from the two binary digits.
0 1 

Octal numbers are built up from the eight octal digits
0 1 2 3 4 5 6 7

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