Sie sind auf Seite 1von 4

Octal Number System

Octal Number System Week: Lecture Date: 07 19/03/2012


Base = 8 or o or Oct 8 symbols: { 0, 1, 2, 3, 4, 5, 6, 7}

Octal to Decimal
(an-1an-2a1a0)8 = (an-1 x 8n-1 + an-2 x 8n-2 + + a1 x 81 + a0 x 80 )10 Example: (127)8 = (1 x 82 + 2 x 81 + 7 x 80 )10 = (64 + 16 + 7)10 = (87)10

Course: Computer Fundamental Instructor: Dr. Arif Mushtaq Topic: Number Systems

Decimal to Octal
Repeated division by 8 (similar in principle to generating binary codes) Example: (213)10 = (? )8
Divide-by -8 213 / 8 26 / 8 3/8 Quotient 26 3 0 Remainder 5 2 3 Octal digit Lower digit = 5 Second digit =2 Third digit =3

Stop, since quotient = 0 Hence, (213)10 = (325)8

Octal Number System


Octal to Binary
Expand each octal digit to 3 binary bits. Example: (725)8 = (111 | 010 | 101)2
1. 2. 3.

Signed Representation
Four methods: methods:
Sign and magnitude Ones complement Twos complement Excess or biased

Binary to Octal
Combine every 3 bits into one octal digit Example: (110 | 010 | 011)2 = (623)8

4.

Sign-andSign-and-magnitude
Representing a number's sign by allocating one sign bit to represent the sign:
Set that bit (often the most significant bit) to 0 for a bit) positive number, and set to 1 for a negative number. The remaining bits in the number indicate the magnitude (or absolute value). value). Example: (8 bit numbers) Hence in a byte with only 7 bits (apart from the sign bit), the magnitude can range from 0000000 (0) to 1111111 (127). Thus you can represent numbers from 12710 to +12710.

Sign-andSign-and-magnitude
Largest positive number: 01111111 = 127 Largest negative number: 11111111 = -127 Decimal 43 encoded in an eight-bit byte this way is eight10101011.

A consequence of this representation is that there are two ways to represent 0


00000000 (+0) and 10000000 (0). (0).

Ones Compliment
Left most bit is sign: 0 for positive, 1 for negative Form negative of number by inverting all bits Example:
0000 0010 is +2 1111 1101 is -2

Twos Complement
Left most bit is sign: 0 positive, 1 negative Form negative of a number by inverting all bits and adding 1 Example:
0000 1110 is +14 1111 0001 + 1 = 1111 0010 is -14

8 bit numbers:
largest positive: 0111 1111 = +127 largest negative: 1000 0000 = -127 two zeros: 00000000 and 10000000

Given n bits, whats the range?


(n(n-2(n-1) to 2(n-1) -1 There will be one more negative number Not ideal, but better than having two types of 0s!

Twos Complement
Given n bits, whats the range?
(0) 000 (-1) 111 (+1) 001

Twos Complement
010 110 001 111 1001101 0110011 Method:
(+2) 010 Take the binary number Get the 1s complement (flip the digits) Add 1 to the result to get the 2s complement

(-2) 110

(-3) 101 100 (-4)

(+3) 011

010 101 + 1 110 001 110 + 1 111 1001101 0110010 + 1

0110011

Twos Complement
8 bit numbers:
largest positive: 0111 1111 = +127 largest negative:1000 0000 = -128 only one representation for zero: (00000000

Excess (Biased) Representation


Effectively moves the scale so the all-zeros allmeans the largest negative number and the all-ones means the largest positive. allHas effect that there are more leading 0 in small numeric numbers which is useful with floating point numbers exponent comparisons (discussed later) Example: 8 bit numbers with offset of 127 ExcessExcess-127 representation

00000000

11111111+1 = 00000000) Note: Implicit here is that the container size is fixed bits fall off the left end.

Excess (Biased) Representation


Bit pattern Value Represented 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8

Representation of Fractions
Binary Point like decimal point signifies boundary between integer and fractional parts: Example 6-bit representation: 6-

ExcessExcess-8

1111 1110 1101 1100 1011 1010 1001 1000 0111 0110 0101 0100 0011 0010 0001 0000

xx.yyyy

21

20

-4 2-1 2-2 2-3 2

10.10102 = 1x21 + 1x2-1 + 1x2-3 = 2.62510


If we assume fixed binary point, range of 6-bit 6representations with this format: 0 to 3.9375 (almost 4)

Fractional Powers of 2
i
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Scientific Notation (in Decimal)


mantissa exponent 6.0210 x 1023 radix (base)

2-i
1.0 1 0.5 1/2 0.25 1/4 0.125 1/8 0.0625 1/16 0.03125 1/32 0.015625 0.0078125 0.00390625 0.001953125 0.0009765625 0.00048828125 0.000244140625 0.0001220703125 0.00006103515625 0.000030517578125

decimal point

Normalized form: no leading 0s (exactly one digit to left of decimal point) Alternatives to representing 1/1,000,000,000
Normalized: Not normalized: 1.0 x 10-9 0.1 x 10-8, 10.0 x 10-10

Representation of Fractions
Consider the decimal number 11 37510. We already know that the binary value of 11 is 10112. Now we need to find the binary number for the fractional part 37510. Perform repeated multiplications on the fractional part
First, we multiply 0.375 by 2 to find the most significant digit (the rightmost digit). Since our result is less than 1, the most significant digit in our answer is 0.

Representation of Fractions
Next, we take the fractional part of our previous result (0.75) and multiply by 2 again. Now the result is greater than 1, so the next digit of our answer is 1. Again we take the fractional part of our previous result (0.5) and multiply by 2. This time our result is exactly 1, so the least significant digit (the leftmost digit) is 1. Since the fractional part of our result is 0, this is the last multiplication needed to find our answer. 0.375 *2 = 0.75 (leftmost digit) 0.75 *2 = 1.5 0.5 *2 = 1.0 (rightmost digit) Then we simply combine the two binary values to get our answer of 1011.0112.

Exercise
Convert the decimal number 145.84375 to binary Answer: 10 01 00 01.11 01 1 Scientific Notation (in Binary)

Floating Point Representation (IEEE-754) (IEEENormal format: +1.xxxxxxxxxxtwo*2yyyytwo Multiple of Word Size (32 bits) single precision
1 bit sign, 8 bit exponent, 23 bit fraction.

mantissa

exponent 1.0two x 2-1 radix (base)

binary point

Floating Point Representation (IEEE-754) (IEEEDouble precision format


uses 64 bits 1 bit sign, 11 bits exponent, 52 bits fraction