Title: Number System: Representation and code
1Number System Representation and code
2Data Representation Unit and Processing Unit
- In order to make a computer work, it is necessary
to convert the information we use in daily life
into a format that can be understood by the
computer. - Binary (base 2)
- Binary digit Bits 0, 1Bytes 00000000
11111111Words 0000000000000000
1111111111111111 - Octal (base 8)
- Octal digital 0,1,2,3,4,5,6,7
- Hexadecimal (base 16)
- Hexadecimal digit 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
- base N
3base N Example
Weight summation method
4Decimal to Binary Conversion
- Weight summation method
- Repeating Division method
- Repeating Multiplication method
5Repeating Division Method
4310
43 2 21 remainder 1
21
21 2 10 remainder 1
10 2 5 remainder 0
1010112
5 2 2 remainder 1
2 2 2 remainder 0
1 2 0 remainder 1
6Repeating Multiplication method
0.312510
0.3125 x 2 0.625 carry 0
0.625
0.01012
0.625 x 2 1.25 carry ?
0.25
1
0.25 x 2 0.5 carry 0
0.5 x 2 1.0 carry 1
7Conversion Between Bases
-
- Base 2 Base 2
- Base 3 Base 3
- Base 4 Decimal Base 4
-
- Base R Base R
- There are shortcuts for Base 2,8,16
Generally, conversion between bases can be done
using decimal numbers
8Conversion Binary-Octal/Hexadecimal
- BinarygtOctal Grouped 3-bit from radix point
- OctalgtBinary Invert
- BinarygtHexadecimal Grouped 4-bit from radix
point - HexadecimalgtBinary
9Binary Arithmetic Operation
- Addition
- Subtraction
- Multiplication
10Binary Arithmetic Operation
- ADDITION
- Similar to decimal
- Example
- 110112 64710
- 100112 53710
- ----------------------
---------------------- - 1011102 118410
- ----------------------
----------------------
11Binary Arithmetic Operation
- SUBTRACTION
- Example
- 110112 64710
- 100112 - 53710 -
- ----------------------
---------------------- - 001102 9010
- ----------------------
----------------------
12Binary Arithmetic Operation
- MULTIPLICATION
- Example
- 110112 64710
- 100112 x 53710 x
- -------------------------------------------
--------------------------------------------
11011 4529 - 110110 19410
- 0000000 323500
- 00000000
- 110110000 -----------------------------
--------------- - -------------------------------------------
34743910 - 10000000012
13Signed Number Representations
- In mathematics, negative numbers in any base are
represented in the usual way, by prefixing them
with a "-" sign. - However, on a computer, there are various ways of
representing a number's sign. - Four methods of extending the binary numeral
system to represent signed numbers - sign-and-magnitude
- ones' complement
- two's complement
- excess-N
14Sign-and-magnitude
- Negative number always written with sign at the
front - Example
- -2010
- -10010
- In computer memory, sign is represent by number
- 0 for
- 1 for -
Magnitude
Sign
15Sign-and-magnitude
- Some early binary computers (e.g. IBM 7090) used
this representation.
Value 0 0 0000000 (0)10 1 0000000 - (0)10
16Ones' complement
- The ones' complement form of a negative binary
number is the bitwise NOT applied to it the
complement of its positive counterpart. - Like sign-and-magnitude representation, ones'
complement has two representations of 0 00000000
(0) and - 11111111 (-0).
17Ones' complement
- This numeric representation system was common in
older computers the PDP-1 and UNIVAC 1100/2200
series, among many others, used ones'-complement
arithmetic.
18First Complement
- Number x,
- n-bit can represent first complement
- -x 2n - x - 1
- Example
- -(1)10 (28 - 1 - 1)10
- 25410
- 111111101s
19Ones' complement
- ISSUE
- Addition of -1 to 2
20Two's complement
- The problems of multiple representations of 0 and
the need for the end-around carry are
circumvented by a system called two's complement.
- In two's complement, negative numbers are
represented by the bit pattern which is one
greater (in an unsigned sense) than the ones'
complement of the positive value. - In two's-complement, there is only one zero
(00000000). - Negating a number (whether negative or positive)
is done by inverting all the bits and then adding
1 to that result. - 11111101s
- 11111112s
11111112s 00000102s ------------------ 10000
0012s
Value for -1
Ones' complement
Twos complement
Addition of -1 to 2
Ignore
21Second Complement
- Number x,
- n-bit can represent second complement
- -x 2n - x
- Example
- -(1)10 (28 - 1)10
- 25510
- 111111112s
22Excess-N
- Excess-N, also called biased representation, uses
a pre-specified number N as a biasing value. - A value is represented by the unsigned number
which is N greater than the intended value. - Thus 0 is represented by N, and -N is represented
by the all-zeros bit pattern.
23Base -2
- In conventional binary number systems, the base,
or radix, is 2 thus the rightmost bit represents
20, the next bit represents 21, the next bit 22,
and so on. - However, a binary number system with base -2 is
also possible. - The rightmost bit represents (-2)0 1, the next
bit represents (-2)1 -2, the next bit (-2)2
4 and so on, with alternating sign.
24Comparison table
25N Complement
-x 2n - x Bn - X B Base n no. of bit X
value
- -x 2n - x - 1
- (Bn - 1) - X
- B Base
- n no. of bit
- X value
- one complement for (0101)2
- (24-1)-01011s
- 1111 - 01011s 10101s
- ninth complement for (22)10
- (102-1)-229s
- 99 - 229s779s
two complement for (0101)2 (24-0101)2s (10000 -
00101)2s 10112s tenth complement for (22)10
(102-22)10s (100 22)10s7810s
26Subtraction using B Complement
- Given two n-digit base-B unsigned numbers,
- I J, Subtraction for (I-J) is as
- Add I to B-complement for J
- ? (5 N - 3 )10
- (2 N)10 N 2n 28
- (2 256)10
- (100000010)2s ? (00000010)2s
- ? (5 - 3 10n)10s N 10n 101
- (2 10)10s
- (12)10s ? (12 - 101)10
- ? (2)10
510 (-3)10
-x 2n - x (two complement)
E.g. 510 - 310
I (Bn - J) (I - J) Bn
n 1 bit
If I?J, there is one final carry Bn, ignore
final carry to obtain answer as I-J
27Subtraction using B Complement
- If I?J, no final carry Bn,
- (I - J) Bn
- (10 N - 22 )10
- (-12 N)10 N 2n 28
- (-12 256)10
- (11110100)2s
- (10 - 22 10n)10s N 10n 102
- (-12 100)10s
- (88)10s? (88 -102)10
- ? - (12)10
E.g. 1010 - 2210
I (Bn - J) (I - J) Bn
n 2 bits
28Exercise
- Identify the following result using i) Two and
ii) Tenth Complement - 33 10 - 2210
- 01102 - 00102
- 00112 01112
- (33 N - 22)10 ? (11 256)10 ? 1000010112s?
000010112s - (33 N - 22)10 ? (11 102)10s ? (111)10s ?
(11)10 - ? (111-102)10 ? (11)10
- (0110 N - 0010)2 ? (0100 28)2s ? (100000100)2s
? (00000100) 2s - (0100 24)2s ?
(10100) 2s ? (0100) 2s - (0110 N - 0010)10 ? (0100101)10s? (410)10s ?
(14)10s ? (4)10 - ?
(14-101)10 ? (4)10 - (0011 N - 0111)2 ? (-0100 28)2s ? (11111100)
2s
29Subtraction using B-1 Complement
- Add I to B-1 complement for J
- I (Bn - 1 - J) (I - J - 1) Bn
- If I?J, there is one final carry Bn,
- ignore final carry to obtain answer as I-J
- If I?J, no final carry Bn
30Subtraction using B-1 Complement
-x 2n - x - 1
- I (Bn - 1 - J) (I - J -1) Bn
- (5 N - 3 - 1)10
- (1 N)10 N 2n 28
- (1 256)10
- (100000001)1s
- ? (00000001 1)2
- ? (00000010)2
- (5 10n - 3 - 1)10 N 10n 101
- (1 10)9s
- (11)9s
- ? (1 1)10
- ? (2)10
E.g. 510 - 310
n 1 bit
- If I?J, there is one final carry Bn,
- ignore and add the final carry to obtain answer
as I-J
31Subtraction using B-1 Complement
- If I?J, no final carry Bn,
- (I - J - 1) Bn
- E.g. 1010 - 2210 (10 N - 22 - 1)10
- (-13 N)10 N 2n 28
- (-13 256)10
- (243)10
- ? (11110011)1s
- 1210 (00001100)2
- -1210 (11110011)1s
- (10 - 22 - 1 10n)9s N 10n 102
- (-13 100)9s
- (87)9s
- ? (871)10s
- ? 88 - 10210
- ? - (12)10
-x 2n - x 1
-x 10n -1 - x (ninth complement)
n 2 bits
-22 (102 -1- 22)9s (87)9s