11111212112s3333-lec04a
DESCRIPTION
lec04_12321112TRANSCRIPT
Number Systems 1/30/12
Decimal number system
Binary number system
Special bit sequences
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,...
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
Binary radix = 2 Octal radix = 8 = 23
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 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111
Octal to Binary Conversion: Expand each octal digit into the equivalent binary code.
Verify:
A byte (8-bit number) is given by two hex digits.
Decimal
Value
Binary
Code
Hex
Code
0 0 0 0 0 0
1 0 0 0 1 1
2 0 0 1 0 2
3 0 0 1 1 3
4 0 1 0 0 4
5 0 1 0 1 5
6 0 1 1 0 6
7 0 1 1 1 7
8 1 0 0 0 8
9 1 0 0 1 9
10 1 0 1 0 A
11 1 0 1 1 B
12 1 1 0 0 C
13 1 1 0 1 D
14 1 1 1 0 E
15 1 1 1 1 F
Memorize this table
Binary to Hexadecimal Conversion
Binary radix = 2 Hexadecimal radix = 16 = 24
· 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.
Example:
1 0 0 0 1 1 1 0 0 . 0 1 0 0 0 12 =
First hex digit
2nd
hex
digit
Bits can be used to represent everything
7-bit ASCII codes to represent characters in a computer
Prefixes
Source:http://ascii-table.com
Source: Slides for the Computer Organization course, Fall 07, from UC Berkely.
Decimal
Value
Binary
Code
Hex
Code
0 0 0 0 0 0
1 0 0 0 1 1
2 0 0 1 0 2
3 0 0 1 1 3
4 0 1 0 0 4
5 0 1 0 1 5
6 0 1 1 0 6
7 0 1 1 1 7
8 1 0 0 0 8
9 1 0 0 1 9
10 1 0 1 0 A
11 1 0 1 1 B
12 1 1 0 0 C
13 1 1 0 1 D
14 1 1 1 0 E
15 1 1 1 1 F
Binary-coded decimal (BCD) system
See the book for algorithms on adding, multiplying, modular arithmetic of binary integers.
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.
1/30/12
Section 4.1, # 40
Also, try #38, section 4.1
Extra: not covered in class