0% found this document useful (0 votes)
12 views35 pages

Chapter 2

The document outlines the concepts of number systems including decimal, binary, octal, and hexadecimal, along with their conversions and arithmetic operations. It also discusses signed number representations such as sign magnitude and two's complement, as well as floating-point numbers. Key topics include the conversion methods, arithmetic rules, and the representation of numbers in various formats.

Uploaded by

dimashsakennnn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views35 pages

Chapter 2

The document outlines the concepts of number systems including decimal, binary, octal, and hexadecimal, along with their conversions and arithmetic operations. It also discusses signed number representations such as sign magnitude and two's complement, as well as floating-point numbers. Key topics include the conversion methods, arithmetic rules, and the representation of numbers in various formats.

Uploaded by

dimashsakennnn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

CS2115 Computer Organization

2025/2026 Sem A

Chapter 2: Number Systems

Department of Computer Science


City University of Hong Kong

1
Outline
• Decimal, Binary, Octal, Hexadecimal Systems
– Conversion between different systems
– Arithmetic
• Signed Number Representation
– Sign Magnitude Number
– Two’s Complement
• Floating-point Number
• BCD, ASCII, Gray …

2
Outline
• Decimal, Binary, Octal, Hexadecimal Systems
– Conversion between different systems
– Arithmetic
• Signed Number Representation
– Sign Magnitude Number
– Two’s Complement
• Floating-point Number
• BCD, ASCII, Gray

3
Decimal System
• 972.5 = 9×102 + 7×101 + 2×100 + 5×10-1

radix
10
𝑛− 1 Radix-10 System
𝑁 = ∑ 𝑎𝑖 ×10 𝑖, 𝑎𝑖 ∈(0 , 1 ,2 , 3 , 4 , 5 , 6 , 7 , 8 , 9)
𝑖=− 𝑚 generalize

R
𝑛− 1 Radix-R System
𝑁 = ∑ 𝑎𝑖 × 𝑹𝑖, 𝑎𝑖 ∈(0 , …, 𝑹−𝟏)
𝑖=− 𝑚
4
Binary, Octal and Hexadecimal
• Binary system (Radix-2) 𝑛− 1
2

12.125 = (1100.001)2 𝑁 = ∑ 𝑎𝑖 ×𝟐 𝑖 , 𝑎𝑖 ∈(0 ,1)


12.125 = 1×23+1×22+0×21+0×20+0×2-1+0×2-2+1×2-3 𝑖=− 𝑚

• Octal system (Radix-8) 8

𝑛− 1
12.125 = (14.1)8 𝑁 = ∑ 𝑎𝑖 ×𝟖 𝑖 , 𝑎𝑖 ∈(0 ,1 , …, 7)
12.125 = 1×81+4×80+1×8-1 𝑖=− 𝑚

• Hexadecimal system (Radix-16) 16

𝑛− 1
𝟏𝟎,𝟏𝟏,𝟏𝟐,𝟏𝟑,𝟏𝟒,𝟏𝟓
12.125 = (C.2)16
𝑁= ∑ 𝑎𝑖 ×𝟏𝟔𝑖,𝑎𝑖 ∈(0,1,… ,9, A ,B ,C , D , E , F)
12.125 = C×160+2×16-1 𝑖=− 𝑚

5
Binary  Octal  Hexadecimal

6
Binary  Octal  Hexadecimal

Octal 2 6 3 5 . 5 4 4 Hexadecimal 5 9 D . B 2

Binary 0 10110011101.101100100 Binary0 10110011101.10110010

7
Conversion to Decimal
– (10101)2 = (1×24+ 0×23+1×22+ 0×21+1×20)10 = (21)10
– (1276)8 = (1×83+2×82+7×81+6×80)10 = (702)10
– (9DF8)16 = (9×163+D×162+F×161+8×160)10 = (40440)10

– (101.11)2 = (1×22+1×20+1×2-1+1×2-2)10 = (4+1+0.5+0.25)10 =(5.75)10


– (8A.E2)16 = (8×161+A×160+E×16-1+8×16-2)10
= (128 + 10 + 14/16 + 8/256)10
= (138.90625)10

8
Conversion from Decimal
• For integers: Radix divide method

(12)10 = ( ? )2
(12)10 = ( 1100 )2

(1582)10 = ( ? )16 (1582)10 = ( 62E )16

9
Conversion from Decimal
• For the fractional part: Radix multiply method
(0.72)10 = ( ? )2 (0.65)10 = ( ? )16
0.72×2 = 1.44 0.65×16 = 10.4

0.44×2 = 0.88 0.4×16 = 6.4

0.88×2 = 1.76 0.4×16 = 6.4


0.76×2 = 1.52 …
0.52×2 = 1.04 (0.65)10 = ( 0.A666 … )16

(0.72)10 = ( 0.10111 … )2

10
Arithmetic
• Direct computation:
– Following essentially the same rule as in decimal, with a different radix
1001 1001 1001 1001
(1001)2+ (1101)2
+ 1101
1
+ 1101
1 + 1101 + 1101
0 10 110 10110

8B 8B
× 23 × 23
(8B)16 × (3)16
1 1A1

11
Arithmetic
• Indirect computation
– First convert everything to decimal, then compute, finally convert back

(1001)2+ (1101)2 (9)10+ (13)10 (22)10 (10110)2

(8B)16 × (3)16 (139)10 × (3)10 (417)10 (1A1)16

12
Outline
• Decimal, Binary, Octal, Hexadecimal Systems
– Conversion between different systems
– Arithmetic
• Signed Number Representation
– Sign Magnitude Number
– Two’s Complement
• Floating-point Number
• BCD, ASCII, Gray

13
Sign Magnitude Numbers
• Naïve representation: the leftmost digit represents sign (sign
digit), the remailing represents the absolute value
– sign digit =0  positive; sign digit = 1  negative
sign magnitude

• Drawbacks
– Addition/subtraction need to consider different cases of different signs
– Complicate circuit and more computation effort
– Rarely used in practice

14
2’s Complement
• Rules:
– Positive numbers are represented in the same way as in sign
magnitude numbers
– Negative numbers are represented as the complement of positive
numbers

• Complement: change 1 to 0, change 0 to 1

15
2’s Complement
+127 01111111
pos(+)
• Consider a 8-bit binary system +126 01111110
+125 01111101
– Cut the number system in half
– Use 00000001 – 01111111 to indicate +1 00000001
positive numbers
0 00000000
– Use 10000000 – 11111111 to indicate -1 11111111
negative numbers -2 11111110

-127 10000001
neg(-)
-128 10000000

16
Sign Bit
+127 01111111
pos(+)
• The most significant bit (MSB) of the +126 01111110
binary numbers is the signed bit +125 01111101

– The MSB is (0) for all positive numbers


• Except 00000000 +1 00000001
0 00000000
– The MSB is (1) for all negative numbers
-1 11111111
– Similar to sign magnitude numbers, this
-2 11111110
allows you to instantly determine whether a
number is positive or negative
-127 10000001
neg(-)
-128 10000000

17
2’s Complement Process
• To calculate the representation of a negative number – using
2’s Complement Process

– First, complement all of the digits in a number.

– Second, add 1.

18
2’s Complement Process
Example #1 5 = 00000101
Complement Digits

11111010
+1
Add 1
-5 = 11111011

Example #2 -13 = 11110011


Complement Digits

00001100
+1
Add 1
13 = 00001101
19
2’s Complement Arithmetic
• Use the 2’s complement process to add the following numbers

POS 9 NEG (-9)


+ POS  + 5 + POS  + 5
POS 14 NEG -4

POS 9 NEG (-9)


+ NEG  + (-5) + NEG  + (-5)
POS 4 NEG - 14
20
POS + POS → POS Answer
• If no 2’s complement is needed, use regular binary addition.

9  00001001
+ 5  + 00000101
14  00001110

21
POS + NEG → POS Answer
• Take the 2’s complement of the negative number and use regular binary
addition.

9  00001001
+ (-5) + 11111011
4  1]00000100
8th Bit = 0: Answer is Positive
Disregard 9th Bit

00000101
 2’s
11111010 Complement
Process
+1
11111011
22
POS + NEG → NEG Answer
• Take the 2’s complement of the negative number and use regular binary
addition.

(-9) 11110111
+ 5  + 00000101
-4  11111100
8th Bit = 1: Answer is Negative

11111100 00001001
To Check:   2’s
Perform 2’s
Complement 00000011 11110110 Complement
On Answer +1 Process
+1
00000100 11110111
23
NEG + NEG → NEG Answer
• Take the 2’s complement of both negative numbers and use regular
binary addition.
2’s Complement
(-9)  11110111 Numbers, See
Conversion

+ (-5)  + 11111011 Process


In Previous Slides

-14  1]11110010
8th Bit = 1: Answer is Negative
Disregard 9th Bit
11110010
To Check: 
Perform 2’s
Complement 00001101
On Answer +1
00001110
24
Outline
• Decimal, Binary, Octal, Hexadecimal Systems
– Conversion between different systems
– Arithmetic
• Signed Number Representation
– Sign Magnitude Number
– Two’s Complement
• Floating-point Number
• BCD, ASCII, Gray

25
Binary with Fractional Part
• Recall that in binary number system
– (1001.1010)2 = 23 + 20 +2-1 + 2-3 =9.625

• If we fix the position of the point Point is here

0 0 0 0 0 0 0 1 0 1 1 0 1 0 1 1

• We are not able to represent small numbers with high precision


Point is here
1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0
• We are not able to represent large numbers

26
Floating-Point Numbers
• 32-bit Binary Floating-Point Numbers
• value = (+/- Significand × 2E’)
– Sign bit: 0positive; 1negative
– Biased Exponent (E)
• Biased exponent E = real exponent value E’ + bias
• bias=2K-1 - 1, K=8 (8-bits of exponent), bias = 127
– Significand
• Normalized number: represent 1.xxx
• The most significant digit is always 1, so we do not need to store this information
• Thus, 23-bit is used to store 24-bit significand

27
Floating-Point Numbers
• 32-bit Binary Floating-Point Numbers
1 10000100 10100000000000000000000
• value = (+/- Significand × 2E’)
negative
– Sign bit: 0positive; 1negative Biased exponent E = 132
– Biased Exponent (E) Real exponent value E’ = 132 – 127 = 5
Significand = 1 + 0.101000... (binary)
• Biased exponent E = real exponent value E’ + bias
= 1 + 0. 625 (decimal)
• bias=2K-1 - 1, K=8 (8-bits of exponent), bias = 127
So the value of the number is
– Significand -1.625 × 25
• Normalized number: represent 1.xxx
• The most significant digit is always 1, so we do not need to store this information.
• Thus, 23-bit is used to store 24-bit significand

28
Outline
• Decimal, Binary, Octal, Hexadecimal Systems
– Conversion between different systems
– Arithmetic
• Signed Number Representation
– Sign Magnitude Number
– Two’s Complement
• Floating-point Number
• BCD, ASCII, Gray

29
BCD: Binary-Coded Decimal
• 4-bit binary form to encode ten numbers from 0 to 9

30
BCD: Binary-Coded Decimal
• 4-bit binary form to encode ten numbers from 0 to 9

31
BCD: Binary-Coded Decimal
• 4-bit binary form to encode ten numbers from 0 to 9

32
BCD: Binary-Coded Decimal
• 4-bit binary form to encode ten numbers from 0 to 9

137 10001001 0001 0011 0111


33
ASCII Code
• ASCII: American Standard Code for Information Interchange
• ASCII encodes 128 specified characters into 7-bit integers

34
Gray Code
• An encoding of numbers so that adjacent numbers have a
single digit differing by 1

35

You might also like