Sie sind auf Seite 1von 18

# Philosophy

of

number

systems:

## To convert a number from one system (decimal, binary, octal,

hexadecimal) to its equivalent in one of the other, we have different types of number systems, namely 1. Decimal systems 2. Binary systems 3. Octal systems 4. Hexadecimal systems

## 1. Decimal Number System:

Decimal means base 10 (the prefix dec). In any number system, given the base (often referred to as radix), the number of digits that can be used to count is fixed. For example in the base 10 number system, the digits that can be used to count are 0,1,2,3,4,5,6,7,8,9. Generalizing that for any base b, the first b digits (starting with 0) represent the digits that are used to count. When a number b has to be represented, the place values are used.

Example: Consider the number 1234.567. It is represented as 1*103+ 2*102 + 3*101 + 4*100+ 5*10-1+ 6*10-2+ 7*10-3 Where: 5 is in the tenths place

## 6 is in the hundredths place 7 is in the thousandths place

In the above equation, the representation includes digits both to the left and to the right of the decimal point. 2. Binary Number System : Binary means base 2 (the prefix bi). The 0, 1 used in the binary system are called binary digits (bits). The bit is the smallest piece of information that can be stored in a computer. It can have one of two values 0 or 1. Think of a bit as a switch that can be either on or off. For example,

From the hardware perspective, ON and OFF can be represented as voltage levels (typically 0V for logic 0 and +3.3 to +5V for logic 1). Since only two values can be stored in a bit, we combine a series of bits to represent more information.

Example: Consider the binary number 1101.101. It can be represented as: 1*23+ 1*22 + 0*21 + 1*20+ 1*2-1+ 0*2-2+ 1*2-3 The same notation is applicable to real numbers represented in binary notation. The equivalent decimal number is 13 + 0.5 + 0 + 0.125 = 13.625

To represent larger numbers, we have to group series of bits. Two of these groupings are of importance: Nibble - A nibble is a group of four bits Byte - A byte is a group of eight bits 3. Octal Number System: Octal means base 8 (the prefix octal). 8 different possible digits are 0,1,2,3,4,5,6,7. Each position in decimal number is weighted by a factor of 8.

4. Hexa Decimal Number System: Hexa Decimal means base 16 (the prefix Hex). Composed of 16 numerals or symbols 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. Use 4 bits group

Decimal 0 1 2 3

Binary 0 1 10 11

Octal 0 1 2 3

Hexa Decimal 0 1 2 3

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111 10000 10001 10010 10011

4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23

4 5 6 7 8 9 A B C D E F 10 11 12 13

## Conversions between Number Systems:

Decimal to binary Decimal to octal Decimal to hex Binary to decimal Binary to octal Binary to hex Octal to decimal Octal to binary Octal to hex Hex to decimal Hex to binary Hex to octal

Decimal to binary: Repeatedly dividing the decimal number by 2and writing down the reminder after each division until a quotation of 0 is obtained.

Decimal to octal: Repeatedly dividing the decimal number by 8 and writing down the reminder after each division until a quotation of 0 is obtained. The reminder can be obtained by multiplying the decimal fraction by 8.

Example: 266/8 = 33.25 The remainder becomes; 0.25 x 8 = 2 Decimal to hex: Repeatedly dividing the decimal number by 16 and writing down the reminder after each division until a quotation of 0 is obtained. T he reminder can be obtained by multiplying the decimal fraction by 16.

Example:

## 214/16 =13.375 The remainder becomes; 0.375 x 16 = 6

Binary to decimal: Summing together the weights of the various positions in the binary number.

Binary to octal: The bits of binary number are grouped of three bits starting at the LSB. Then each group is converted to its octal equivalent.

Binary to hex: The binary number is grouped into groups of 4 bits and each group is converted to its equivalent hex digit. Zeros are added, as needed, to complete 4 bit group.

Octal to decimal: Multiply each octal digit by its positional weight. Then sum all together.

Octal to binary: Convert each octal digit to its 3 bit binary equivalent.

Hex to decimal:

Sum of weight.

Hex to binary: Each hex digit is converted to its four-bit binary equivalent.

## Complement representation of negative numbers:

Negative Numbers:

Negative binary numbers are represented by the - sign followed by the magnitude of the number. The computer however does not have a means of representing signs. The sign has to be captured in the bit pattern itself. Signed Magnitude Representation: The signed magnitude representation uses the most significant bit to determine if the number is positive or negative. The advantage of this notation is that by examining the msb alone, it is possible to determine if the number is positive or negative. The disadvantage however is that one bit pattern is wasted (there are two possible representations for zero) and subtraction cannot be performed using addition alone.

Numbers using 4-bit signed magnitude representation Note: +0 and 0 have different bit patterns. Example: Consider the following operation 7 2. Substituting the bit patterns from the table.

The bit pattern 0001 is 1 but the result should by 5 0101. Ones Complement: The ones complement notation represents a negative number by inverting the bits in each place. Again the limitations of the sign magnitude representation are not overcome (there are two bit patterns used to represent 0 and the addition operation cannot be used to perform subtraction). The ones complement is important because it is very easy to perform the inversion operation in hardware and it forms the basis of computing the twos complement.

Numbers using 1s complement representation Example: Consider the following operation 7 2. Substituting the bit patterns from the table.

The bit pattern 0100 is 4 but the result should by 5 0101. Twos Complement: The twos complement notation builds on the ones complement notation. The algorithm goes as follows: Compute the 1s complement.

Add 1 to the result to get the 2s complement. The twos complement notation has the advantages that the sign of the number can be computed by looking at the msb. The addition operation can be used to perform subtraction. Also, there is only one bit-pattern to represent 0 so an extra number can be represented.

Numbers using 2s complement representation Example: Consider the following operation 7 2. Substituting the bit patterns from the table.

The bit pattern 0101 is 5, which is the expected result. The limitation with the 2s complement notation is that the bit patterns are not in order i.e. comparing the bit patterns alone does not provide any information as to which number is larger.

Binary arithmetic:
Binary Addition: The rules for binary addition are the same as those for any positional number system. One adds the digits column-wise from the right. If the sum is greater than B1 for base B, a carry into the next column is generated. In the case of binary numbers, a sum greater than one generates a carry. Here is the binary addition table:

The first three 1+1=102, or one plus into the twos place. three. The sum is one

entries are self-explanatory. The third entry is one is two; we have a sum of zero and a carry of one The fourth entry is 1+1+1=112, or three ones are and there is a carry into the twos place.

The truth table for one-bit binary addition looks like this:

Addition of Signed Numbers: Binary addition of twos complement signed numbers can be performed using the same rules given above for unsigned addition. If there is a carry out of the sign bit, it is Binary Subtraction: Subtraction is also the same as in decimal, except, 0 -1 = 1 with a 1 borrowed: i.e. borrow 1 from the left and add 2 to the digit on the right, just as you would add 10 if working in decimal.

Binary Multiplication:

## The rules are the same as in decimal.

Notice that no true multiplication is necessary in forming the partial products. The fundamental operations required are shifting and addition. This means we can multiply unsigned or positive integers using only shifters and adders. Binary Division: The rules are the same as in decimal.

Let us divide 0110101 (5310) by 0101 (510). Beginning at the left of the dividend, we move to the right one digit at a time until we have identified a portion of the dividend which is greater than or equal to the divisor. At this point a one is placed in the quotient; all digits of the quotient to the left are assumed to be zero. The divisor is copied below the partial dividend and subtracted to produce a partial remainder as shown below.

Now digits from the dividend are brought down into the partial remainder until the partial remainder is again greater than or equal to the divisor. Zeroes are placed in the quotient until the partial remainder is greater than or equal to the divisor, then a one is placed in the quotient, as shown below.

The divisor is copied below the partial remainder and subtracted from it to form a new partial remainder. The process is repeated until all bits of

the dividend have been used. The quotient is complete and the result of the last subtraction is the remainder.

This completes the division. The quotient is 10102 (1010) and the remainder is 112 (310 ), which is the expected result. This algorithm works only for unsigned numbers, but it is possible to extend it to twos complement numbers.

Binary Codes:
Internally, digital computers operate on binary numbers. When interfacing to humans, digital processors, e.g. pocket calculators, communication is decimal-based. Input is done in decimal then converted to binary for internal processing. For output, the result has to be converted from its internal binary representation to a decimal form. To be handled by digital processors, the decimal input (output) must be coded in binary in a digit by digit manner. One commonly used code is the Binary Coded Decimal (BCD) code which corresponds to the first 10 binary representations of the decimal digits 0-9. The BCD code requires 4 bits to represent the 10 decimal digits. Since 4 bits may have up to 16 different binary combinations, a total of 6 combinations will be unused. The position weights of the BCD code are 8, 4, 2, 1. Other codes (shown in the table) use position weights of 8, 4, -2, -1 and 2, 4, 2, 1. An example of a non-weighted code is the excess-3 code where digit codes is obtained from their binary equivalent after adding 3. Thus the code of a decimal 0 is 0011, that of 6 is 1001, etc.

## Error detecting & error correcting codes:

When a message is transmitted, it has the potential to get scrambled by noise. This is certainly true of voice messages, and is also true of the digital messages that are sent to and from computers. Now even sound and video are being transmitted in this manner. By a digital message, we mean a sequence of 0's and 1's which encodes a given message. What we will seek to do is to add more data to a given binary message that will help to detect if an error has been made in the transmission of the message; adding such data is called an error-detecting code.