You are on page 1of 10

Number Systems

1/30/12

Decimal number system

A position's weight is rk, where k is the number of positions from the decimal point.
To the left of the decimal point, k takes values 0, 1, 2... ,
and to the right, it takes values -1,-2,...

Binary number system

Special bit sequences

Octal number system

Hexadecimal number system

Examples

Base-r representation of a decimal integer


1. Let the given integer be denoted N.

2. By the Division Algorithm, there exist unique N1 and a0 such that


N = N1 r + a0,
0 a0 < r.
a0 is the first digit (rightmost digit) of base-r representation.

3. Applying the Division Algorithm on N1, we get


N1 = N2 r + a1,
0 a1 < r.
a1 is the next digit (on the left) in base-r representation.

4. Repeat this until quotient is zero.


If the Division Algorithm is applied k times, then
ak-1 a1 a0
is the base-r representation of N.

Converting a decimal fraction to base-r notation


Let i=-1, the fractional part be denoted as 0.f
The digits in the fractional part of base-r notation are denoted 0.a-1 a-2 a-3
1. Multiply 0.f with r
Let the result be x.y, where x is the integer part and y is the new fractional part
2. Use x as the ith digit in the fractional part of base-r representation
3. If y is not zero, set i = i-1 repeat steps 1 and 2 with 0.y
Example: Convert 0.62510 to equivalent binary representation.

Binary to Octal Conversion


Octal radix = 8 = 23

Binary radix = 2

Direction conversion is feasible. Starting with the binary point,


(i) group 3 bits at a time, and use their decimal value as an octal digit, and
(ii) pad the left of integer part and the right of fractional part with 0s as needed to makes groups of 3 bits
Octal

Binary

000

001

010

011

100

101

110

111

Octal to Binary Conversion: Expand each octal digit into the equivalent binary code.

Verify:

Binary to Hexadecimal Conversion


Hexadecimal radix = 16 = 24

Binary radix = 2

Hexadecimal system uses 16=24 as the radix.

Group 4 bits of binary number to obtain the corresponding hexadecimal digit. See the table below.

Pad the left of integer part and the right of fractional part as needed to make groups of 4 bits.

Binary
Code

Decimal
Value

Hex
Code

Example:

1 0 0 0 1 1 1 0 0 . 0 1 0 0 0 12 =

10

11

12

13

14

15

Memorize this table

A byte (8-bit number) is given by two hex digits.

Bits can be used to represent everything


7-bit ASCII codes to represent characters in a computer

First hex digit

2nd
hex
digit

Source:http://ascii-table.com

Prefixes

Source: Slides for the Computer Organization course, Fall 07, from UC Berkely.

Binary-coded decimal (BCD) system

Binary
Code

Decimal
Value

Hex
Code

10

11

12

13

14

15

See the book for algorithms on adding, multiplying, modular arithmetic of binary integers.

1/30/12

Section 4.2, # 31.


Show that a positive integer is divisible by 3 if and only if the sum of its
decimal digits is divisible by 3.

Extra: not covered in class

Section 4.1, # 40

Also, try #38, section 4.1

You might also like