NUMBER SYSTEMS
  1. Decimal
  2. Hexadecimal
  3. Binary
  4. Conversion between Binary and Hexadecimal
  5. Negative Numbers   (two's complement)
  6. Machine Dependencies (Precision, Rounding, Max. Integer)

 
 Octal = base 8 notation - Wikipedia


A REVIEW OF BASE 10 (DECIMAL) NOTATION

The decimal or base-10 number system is so common to everyday life that few people understand its evolution or functions. In the decimal number system, all numbers can be represented by combinations of 10 unique digits (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9) located in specific locations or places. Each position to the left is one power of 10 greater than the position to its right.
To determine the value represented by a sequence of digits in a decimal number, multiply each digit by its place value and add the products.  For example:

345.21010 = (3 * 102) + (4 * 101) + (5 * 100) + (2 * 10-1) + (1 * 10-2) + (0 * 10-3)

Although trivial, this example of using the decimal number system can be applied to all positional number systems. All (positional) number systems are built on sequences of digits whose positions correspond to powers of the base value (basen). By understanding how the decimal system works, it is possible to create and use alternative number systems and to convert from one number system to any other.
 
 
 

A REVIEW OF BASE 16 (HEXADECIMAL) NOTATION

Hexadecimal or base-16 is used extensively in computing ("hexa" refers to six and "decimal" mean ten). In the hexadecimal system, numbers are made up of combinations of 16 unique digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F), and positions have place values corresponding to powers of sixteen (16n). In the hexadecimal system, the first left position from the hex point (as opposed to the decimal point in base-10) has a place value of 160 (160=1), the position to the left has a place value of 161 (161=16), and so on. Numbers in the hexadecimal system are written with a subscript of 16 after the rightmost digit to distinguish them from numbers in other systems.  For example:

35B2.116 = (3 * 163) + (5 * 162) + (B * 161) + (2 * 160) + (1 * 16-1)
35B2.116 = (3 * 163) + (5 * 162) + (11 * 161) + (2 * 160) + (1 * 16-1)
35B2.116 = 1228810 + 128010 + 17610 + 210 + 0.062510
35B2.116 = 13476.062510
 
 
 



A REVIEW OF BASE 2 (BINARY) NOTATION

Another number system of great importance to computers and computer programming is the binary or base-2 number system. Numbers in this system are made up of combinations of only two unique digits, 0 and 1. Positions or place values in the binary system correspond to powers of two (2n), just as place values in the decimal system correspond to powers of ten (10n). In a binary number, the first left position from the binary point (as opposed to a decimal point in base-10) has a place value of 20 (20=1), the next position to the left has a place value of 21 (21=2), and so on. Numbers in the binary system have a subscript of 2 after the rightmost digit to distinguish them from numbers in other number systems (101011 binary system = 1010112, 256 decimal system = 25610).  For example:

101011.100012 = (1 * 25) + (0 * 24) + (1 * 23) + (0 * 22)  + (1 * 21) + (1 * 20) + (1 * 2-1) + (1 * 2-5)
101011.100012 = 32 + 0 + 8 + 0 + 2 + 1 + 0.5 + 0.03125
101011.100012 = 43.5312510

Note that 43.5312510 is an approximation of 101011.100012. This is a problem in converting numbers with fractional parts between different number systems. Numbers that can be exactly stated in one system (101011.100012) must be rounded off in other systems (43.5312510). Integer numbers are always exact when transferring between number systems.
 
 
 

CONVERSION BETWEEN BINARY AND HEXADECIMAL

Conversion between binary and hexadecimal and back is a simple operation. To convert from binary to hexadecimal, group the bits into chunks of four, then apply the following conversion table:
 

Decimal Binary Hexadecimal










10 
11 
12 
13 
14 
15 
0000 
0001 
0010 
0011 
0100 
0101 
0110 
0111 
1000 
1001 
1010 
1011 
1100 
1101 
1110 
1111















To convert from hexadecimal to binary, replace the hexadecimal numbers with the four bit binary equivalent in the table above.  For example:

1110000100012 = 1110 0001 00012 = E1116
F4A516 = 1111 0100 1010 01012 = 11110100101001012

The binary system currently is firmly established as a fundamental system for representing data in electronic digital computers. It is, however inconvenient to represent large binary numbers in positional binary because of the large number of digits required.

Note that if we group the digits in groups of four they represent a digit to the base 16. Notice that the way we arrived at the hexadecimal number was by grouping bits together.

Consider the number Z = 10110011. Then X = 1011 and Y = 0011. By grouping the number into groups of four bits we can easily find the hexadecimal equivalent of the number. X = B and Y = 3 so we can say Z = B3.
 
 
 

NEGATIVE NUMBER REPRESENTATION

A negative binary number is represented as the binary number that when added to a positive number of the same magnitude equals zero.
A negative number is the additive inverse of a number. A negative binary number is defined by a 1 in the leftmost digit position.
Most Significant Bit (MSB) indicates the sign of the integer.
     If MSB = 0, then the number is greater than or equal to 0.
     If MSB = 1, then the number is less than 0.

To obtain the (decimal) value of a negative (binary) number, simply take the two's complement of the (binary) value of the given negative (decimal) number and put a minus sign in front of it.  For example:  -310=11002.  The decimal value is 11002 with a negative sign in front of it.
0011 = 310
Subtract 10000 - 0011 = 1101. That is, 1101 represents the negative number -310.
1101 = -310

Another quick way to find the representation of a negative number is to find the one's complement and then add one to realize the two's complement.
0011 = 310
1100 = one's complement of 3        (diminished radix-complement)       XOR every bit with 1
1101 = two's complement of 3        (radix-complement)
So, 1101 is the binary representation of -3.
1101 = -310

XOR is a Logical Operator.  True=1  False=0  The XOR operator requires one of the two conditions to be true (1) for the condition to be true.  If both conditions are true (1), the compound condition is false (0).  Likewise, if both conditions are false (0) the compound condition is also false.     (0 xor 0)=0   (1 xor 1)=0   (1 xor 0)=1   (0 xor 1)=1
Note that in practice, this means simply reversing all the zeros and ones.



MACHINE DEPENDENCIES

PRECISION AND ROUND-OFF ERRORS

Precision is the number of bits that a computer uses to represent its floating point numbers. The more bits that are used, the more accurate a representation is going to be made. If the represented value has more decimal places than the machine's precision can handle, then the value is rounded off. When calculations are done, they use these approximated values. The difference between the "real" answer and the calculated one is due to round-off error. A correlation can be made between the machine precision and the round-off error. The greater the precision a computer has the smaller the resulting round-off error.

MAXIMUM INTEGER

The maximum integer is the largest positive number that can be stored in an integer variable. This depends on the word size and is therefore machine dependent. The largest positive number is where all the bits of a word are set to 1's except the sign bit. Adding one to this number will cause the number to become negative ie: the number will "roll over" like an odometer.

One way to find the maximum integer is to add one until the number is smaller than the previous one. If your word size is large this takes a long time. There is a more efficient method. Source:
http://www.cs.uregina.ca/dept/manuals/Manuals/3_0NumRep/3_Num_Rep.html
http://www.cs.uregina.ca/dept/manuals/Manuals/3_0NumRep/3_Num_Rep_ToC.html