0% found this document useful (0 votes)
27 views52 pages

Unit6 Numbers

Uploaded by

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

Unit6 Numbers

Uploaded by

khdguata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Number Systems and Number

Representation
Index: Recap your High School maths

❑ (𝑦2)(𝑦5)= 𝑦2+5 =𝑦 7
1
❑ (𝑥1/2) = 𝑥, 𝑥 = 𝑥2
−2

❑ (𝑦 𝑎 ) 3 = (𝑦 𝑎 )(𝑦 𝑎 )(𝑦 𝑎 ) = 𝑦 3𝑎

❑ (𝑦 2𝑎 ) 3 = (𝑦 2𝑎 )(𝑦 2𝑎 )(𝑦 2𝑎 ) = 𝑦 6𝑎

❑ (𝑦 𝑚 ) (𝑦 𝑘 ) = 𝑦(𝑚+𝑘)
𝑚
𝑦
❑ (𝑦 𝑚 ) (𝑥 ) = 𝑥 𝑘
−𝑘
❑ 1.1 Number Systems
❑ 1.2 Signed and Unsigned Binary Numbers
❑ 1.3 1’s Complement
❑ 1.4 Hexadecimal Number
❑ 1.5 Binary Arithmetic
❑ 1.6 Fixed-Point Representation
❑ 1.7 Floating-Point Representation
❑ 1.8 Floating-Point Arithmetic
Number Systems
Types of Numbers
❑ Natural Numbers 𝑵
❑ Integers 𝒁
❑ Rational Numbers 𝑸
❑ Real Numbers 𝑹
❑ Complex number 𝑪
-1= 𝑖 2 , 𝑖𝑚𝑎𝑔𝑖𝑛𝑎𝑟𝑦 𝑛𝑢𝑚𝑏𝑒𝑟

Can you give an example of an


irrational number?
Natural Numbers 𝑵
❑ The most basic set of numbers.
❑ The set of all positive integers,
❑ The numbers used to count objects.
❑ The earliest number set in existence.
❑ The capital letter 𝑵,
 The usual denotation of the set of natural numbers.
❑ Example of natural numbers:
 {1, 2, 3, … } “0” is not usually considered as natural number
Integers 𝒁
❑ The set of integers 𝒁,
 Take the set of natural numbers then add to it the
negatives of all natural numbers.
❑ While +/− and × are defined on 𝒁, ÷ is not,
 Dividing one integer by another may not yield a
third integer as the result.

 Example of integers:
 {. . . , −3, −2, −1, 0, 1, 2, 3, . . . }
Rational Numbers 𝑸
❑ The set of rational numbers 𝑸,
 Expand the set of integers by adding to it all the quotients
(ratios) of integers.
𝒂
The set of numbers of the form , where 𝒂 and 𝒃 are integers
𝒃
(and 𝒃 ≠ 𝟎, of course).
❑ Division (÷) is defined on rational numbers
 Any rational number divided by any nonzero rational yields
another rational number.
1
❑ Example of rational number: {−0.1}, as a fraction {− }.
10
• Irrational Number: Any number cannot be expressed in a
𝒂
form of 𝒃
, where 𝒂 and 𝒃 are integers.
• Typical irrational number, 𝜋 (22/7 is an approximate only) , e (Euler number)
Real Numbers 𝑹
❑ A subset of the complex numbers.
❑ A real number 𝑟 is just a complex number
without the imaginary part, 𝑟 + 0𝑖 (in
engineering we use j instead of i.)
❑ The set of all real numbers is usually denoted
by the capital letter 𝑹.
❑ Example of real numbers :
4
 {1, −10, −0.67, , 𝜋, 2, 187}
5
Exercise Q1

1. Is “0” a rational number?

2. Is infinity a rational number?


Exercise Q2
❑ Which of the following is a correct statement?

A. Sum of two irrational numbers is always irrational.


B. Sum of a rational and irrational numbers is always an
irrational number.

C. Square of an irrational number is always a rational


number.

D. Sum of two rational numbers can never be an integer.


Exercise Q3
❑ Is the sum of two odd integers odd? And why?

▪ The sum of two odd integers is EVEN.

▪ If 𝑚 and 𝑛 are odd integers, then there exist integers


𝑎, 𝑏 such that 𝑚 = 2𝑎 + 1 and 𝑛 = 2𝑏 + 1.

▪ 𝑚 + 𝑛 = 2𝑎 + 1 + 2𝑏 + 1 = 2(𝑎 + 𝑏 + 1). Since (𝑎 +


𝑏 + 1) is an integer, 𝑚 + 𝑛 must be even.
Complex Number
Theorem DeMoivre’s Theorem
Euler’s Number & Euler’s Identity
Important Euler’s identity 𝑒 𝑖𝜋 = -1

𝑥 𝑥2 𝑥3 𝑥𝑛
The above is 𝑒 or 𝑒 1 . For 𝑒 𝑥 , 𝑒𝑥 = 1+ + + …+
1! 2! 3! 𝑛!
It happened that they used infinite series to model sine and cosine and found
𝑥2 𝑥4 𝑥6 𝑥 𝑥3 𝑥5 𝑥7 So similar to e, any
𝑐𝑜𝑠 𝑥 = 1 − + − +… sin 𝑥 = − + − +…
2! 4! 6! 1! 3! 5! 7! relationship?
𝑥 𝑥2 𝑥3 𝑥4 𝑥5 𝑥6 𝑥7
Also, 𝑐𝑜𝑠 𝑥 + sin 𝑥 = 1 + − − + + − − +…
1! 2! 3! 4! 5! 6! 7!
very similar to Euler’s number except the sign

• In order to make the above (cos + sin) expression equal to Euler’s series, need
to multiple something square to give negative in the Euler’s series expression.
• It means to multiple something -1= 𝑖 2 but no such thing at that time.
• Mathematician then (invented) the imaginary number , -1= 𝒊𝟐
2 3 4 𝑛
𝑖𝑥 (𝑖𝑥) (𝑖𝑥) (𝑖𝑥) 𝑖𝑥
𝑒 𝑖𝑥 = 1 + + + + +⋯ ,
1! 2! 3! 4! 𝑛!

where the invention of the imaginary number i


𝑖𝑥
𝑖𝑥 𝑥 2 𝑖𝑥3 𝑥 4 𝑖𝑥5 𝑥 6 𝑖𝑥7
𝑒 =1+ − − + + − − …
1! 2! 3! 4! 5! 6! 7!
Regroup the real parts and imaginary parts:
𝑥2 𝑥4 𝑥6 𝑥8 𝑖𝑥 𝑖𝑥3 𝑖𝑥5 𝑖𝑥7
𝑖𝑥
𝑒 = 1− + + + ⋯+ − + − …

2! 4! 6! 8! 1! 3! 5! 7!

𝑥2 𝑥4 𝑥6 𝑥8 𝑥 𝑥3 𝑥5 𝑥7
𝑒 𝑖𝑥 = 1− + − + + ⋯ +𝒊 − + − …
2! 4! 6! 8! 1! 3! 5! 7!
𝑥2 𝑥4 𝑥6
𝑥 𝑥3 𝑥5 𝑥7
since 𝑐𝑜𝑠 𝑥 + 𝑖sin 𝑥 = 1 − + − +… + 𝑖 − + − …
2! 4! 6! 1! 3! 5! 7!

𝑇ℎ𝑢𝑠 𝑒 𝑖𝑥 = 𝑐𝑜𝑠 𝑥 + 𝒊 sin 𝑥

Also for a special case that put 𝑥 = 𝜋, since cos 𝝅 = −1, sin 𝝅 = 0
we have the important 𝐸𝑢𝑙𝑒𝑟′𝑠 𝐼𝑑𝑒𝑛𝑡𝑖𝑡𝑦

𝒆𝒊𝝅= -1
Euler’s Identity
𝑒 𝑖𝑥 = 𝑐𝑜𝑠 𝑥 + 𝒊 sin 𝑥
𝐼𝑚
𝑖 𝑒 𝑖𝑥 = cos 𝑥 + 𝑖 sin 𝑥

sin𝑥
It is a unit circle (radius = 1)
𝑥
0 cos 𝑥 1 𝑅𝑒
The magnitude of 𝑒 𝑖𝑥 is1.

As 𝑥 increases, the complex number 𝑒 𝑖𝑥 = cos 𝑥 + 𝑖 𝑠𝑖𝑛 (𝑥) travels


counterclockwise around the unit circle.
𝐼𝑚 𝐼𝑚 𝜋
𝑖 𝑖 𝑒𝑖2 = 𝑖
𝑒 𝑖𝑥 = cos 𝑥 + 𝑖 sin 𝑥

𝑒 𝑖𝜋 = −1
𝑒0 = 1
𝑥
0 1 𝑅𝑒 0 1 𝑅𝑒
𝑒 2𝜋𝑖 = 1

3𝜋
𝑒𝑖 2= −𝑖

Used in AC electriccircuit
A brief introduction on digital technology
Instruction Set Architecture ISA

- An Instruction Set
Architecture (ISA) defines the Instruction sets
interface between software architecture
and hardware.

Software is converted to
machine instructions
(assembly language) using
software
(compiler/interpreter).

Then the instructions are


executed (in binary codes) in
hardware.
Signed and Unsigned Binary
Numbers
Exponents
4.0 = 4 (100) 4.0 = 4 (100)

40.0 = 4 (101) 0.4 = 4 (10−1)


400.0 = 4 (102) 0.04 = 4 (10−2)
4000.0 = 4 (103) 0.004 = 4 (10−3)

40000.0 = 4 (104) 0.0004 = 4 (10−4)

We are basically moving the radix point “.” left or right

• We will use this fundamental concept for floating


point representation of numbers.

• Floating point is an important concept for


computer science and computer engineering.
Representing numbers
= 300 + 40 +5 + 0.8 + 0.06 + 0.005
reminder
2 | 345 1
2 | 172 0 LSB 0.865 ≈ . 1101 1101 8 bit
2 | 86 0 0.865 ≈ .1101 1101 0111 12 bits
2 | 43 1
2 | 21 1 0.865 ≈ .1101 1101 0111 00001 17 bits
2 | 10 0
2 | 5 1
3 | 2 0 Most of the time, we cannot use a binary
2 | 1 1 MSB number to represent a fraction exactly.
2 | 0
Increasing the number of bits cannot
1 0101 1001 represents a fraction exactly.
MSB LSB
Binary Numbers Representation (cont)
❑ First 345/2 = 172 (remainder 1) – Least Significant Bit (LSB)
❑ Next 172/2= 86 (remainder 0)
❑ Then 86/2 = 43 (remainder 0)
❑ Then 43/2 = 21 (remainder 1)
❑ Then 21/2 = 10 (remainder 1)
❑ Then 10/2 = 5 (remainder 0)
❑ Then 5/2 = 2 (remainder 1)
❑ Then 2/2 = 1 (remainder 0)
❑ Then 1/2 = 0 (remainder 1) – Most Significant Bit (MSB)
❑ End.
❑ This will lead to a binary number [1 0101 1001]
MSB… .LSB
❑ 256 128 64 32 16 8 4 2 1

1 0 1011001 = 1+8+16+64+256 = 345


Represent a fraction in binary
Example: to represent a fraction 0.865 in binary 4 bits form
MSB
❑ First 0.865 x 2 = 1.730 (1st digit left of decimal is 1)
❑ Next 0.730 x 2 = 1.460 (1st digit left of decimal is 1)
❑ Then 0.460 x 2 = 0.920 (1st digit left of decimal is 0)
❑ Then 0.920 x 2 = 1.840 (1st digit left of decimal is 1) LSB

❑ Note: Usually it is hard to represent a fraction exactly. More bits


are needed to increase the accuracy.

0.865 in 4 bits binary ≈ .1101 (approximate only)

0.5 + 0.25 + (0)(0.125)+ 0.0625 =0.8125 4 bits

0.86499977111… ≈ .1101 1101 0111 0000 101 17 bits


Binary Number Representation

0.5 0.25 0.125 0.0625


16 8 4 2 1 ½ ¼ 1/8 1/16

29.625= 11101. 1 0 1 0

• We have difficulty to use binary


to represent
16 8 4 2 1 29.779 in an exact way.
29= 11101
• We may need many more bits to
MSB, Most LSB, Least approximate the “.779 “exactly
significant bit significant bit or just accurately.

• . 11000111011011001001
Represent a fraction in binary
Example: to represent a fraction 0.625 in binary 4 bits form
MSB
❑ First 0.625 x 2 = 1.25 (1st digit left of decimal is 1)
❑ Next 0.25 x 2 = 0.5 (1st digit left of decimal is 0)
❑ Then 0.5 x 2 = 1.0 (1st digit left of decimal is 1)
❑ Then 0.0 x 2 = 0.000 (1st digit left of decimal is 0) LSB

Note: WE have an exact representation here. Usually we do not


have and more bits are needed to increase the accuracy.

0.625 in 4 bits binary = .1010 (exact)

0.5 + (0)0.25 + (1)(0.125)+ (0)(0.0625) =0.625 4 bits


Addition- Unsigned Numbers

❑ Adding unsigned numbers:


 E.g., add the numbers 06 10 = 0110 2 and 07 10 = 0111 2
 Answer: 6 + 7 = 13 10 = 1101 2

❑ The only difficulty adding unsigned numbers occurs when


you add numbers that are too large that exceeds the range
of the given bit length.
 Consider 13+5.

 The result is a 5 bit number.


 The carry bit from adding the two most significant bits
represents a results that overflows.
Signed Binary Numbers

❑ Representing negative binary number

❑ The signed numbers are represented in three


ways,
 Sign-Magnitude form
 1’s Complement
 2's Complement
Sign-Magnitude Form
Reduced range due to using MSB as sign bit

Signed binary numbers use


the MSB as a sign bit to
indicate the number is +ve
or –ve number.
Sign-Magnitude Form (cont)

Sign 4 2 1 4 bits representation


1111 -7
1110 -6
1101 -5
1100 -4
1011 -3
1010 -2
1001 -1
1000 -0 Two 0’s problem
0000 0
0001 1
0010 2 Weird result
0011 3 1101 -5
0100 4 +0101 +5
0101 5
0110 6 1 0010 +2
0111 7
1’s Complement (Make 1 into 0, 0 into 1)

842 1 4 bits representation


1000 -7
1001 -6
1010 -5
1011 -4
1100 -3
1101 -2
1110 -1
1111 -0 Still have two 0’s problem
0000 0
0001 1
0010 2 okay results
0011 3
0100 4 1010 -5 1011 -4
0 1 01 5 +0101 +5 + 0100 +4
0 1 10 6 1111 -0 1111 -0
0 1 11 7
2’s Complement
❑ By inverting each bit of a number and adding plus 1 to
its least significant bit.
❑ The binary number also has an extra bit for sign
representation as a sign-magnitude form.
2’s Complement (cont.)
❑ Example 1: 0100 (representing +4 in a 4 bits case)
1011 Invert all the bits
+ 0001
= 1100 (-4)
-8+4 =-4

❑ Example 2: 0110 (representing =6 in a 4 bits case)


1001 Invert all the bits

+ 0001
= 1010 (-6)
-8+ 2 = -6
2’s Complement (cont.)

842 1
1001 -7
1010 -6 Normal result
1011 -5
1011 -5
1100 -4 +0101 +5
1101 -3 0000 0
1110 -2
1111 -1
0000 0 No two 0’s problem
0001 1
0010 2
0011 3 1001 -7
0100 4 -8 + 1 = -7
0101 5
0110 6 The MSB use as both sign
0111 7 bit and magnitude
Substraction in 2’s complement
13 - 9 = 4 (6 bits representation)
13 : 00 1 1 0 1
9 : 00 1 0 0 1
-9 in 2’s complement: 11 0 1 1 0
+ 1
-9= 11 0 1 1 1
1 1 11 1 carry
13 + (-9) 00 1 1 0 1
+ 11 0 1 1 1
1 00 0 1 0 0 = 4

overflow
Hexadecimal Number (base 16)
Hexadecimal to Decimal
❑ The representation of a hexadecimal number
into decimal form
Decimal to Hexadecimal
❑ 23 10
 23/16 = 1, remainder 7
1
 = 0, remainder 1
16
23 10 = 17 16

❑ 510 10
 510/16 = 31, remainder is 14 10 = 𝐸 16
 31/16 = 1, remainder is 15 10 = 𝐹 16
 1/16 = 0, remainder 1
 510 10 = 1𝐹𝐸 16
Binary to Hex Conversion

1. Divide binary number into 4-bitgroups

01 1 0 0 0 0 1 1 1 0 0
Pad with 0’s
If unsigned number

2. Substitute hex digit for each group

61C16
Hexadecimal to Binary Conversion
Example

1. Convert each hex digit to equivalentbinary

(1 E 9 C)16

(0001 1110 1001 1100)2


Exercise: Number System
Convert the following hexadecimal number

(3𝐹𝐴7)16
to
1) decimal number
2) 16 bits equivalent binary number.
Exercise: Number System
1) Convert to decimal number:

We use the power series expansion:


3𝐹𝐴7 16

= 3 × 163 + 15 × 162 + 10 × 161 + 7 × 160


= 12288 + 3840 + 160 + 7
= 16295 10
Exercise: Number System
2) Hexadecimal to binary conversion is straightforward:
Convert each hex digit to 4-bit binary number.

Hex 3 F A 7
↓ ↓ ↓ ↓
Bin 0011 1111 1010 0111

Therefore, 3𝐹𝐴7 16 = 0011 1111 1010 0111 2.

Hex addition: carry 11


F+B+1=26= 1A 1 is carry
3F8
+ 5B3
9AB
Fixed-Point Representation
Fixed-Point Representation

❑ The smallest positive number and largest positive number which can be
store in a 32-bit representation (1 sign bit, 15 bits integer, 16 bits
fraction) as the below format.
.
11 (2 bits) = 3 = 22 −1
1111 (4 bits) = 15 = 24 - 1

❑ The smallest positive number is 2−16 ≈ 0.000015 approximate. 15 bits integer

• The largest positive number is 215 − 1 + 1 − 2−16 =


32768 − 1 + 0.9999847412 … = 32767.9999847. . .
• Fix the radix point gives less flexibility to represent a number in terms of range and
accuracy.
• Floating point: For the same 32 bits, the radix point “.” can be moved to either left or
right to increase accuracy or range.
0.1111 (4 bits)
=.5+.25+.125+.0625=0.9375
1
=1- 2−4 = 1 − =0.9375
16
Floating-Point
Representation
Class work: Exponent and shift of radix point

Decimal number
❑ 1. (1 0.110)10 = 101.10 x 10−1
❑ 2. (0.1 0110)10 = 101.10 x? 10−3

❑ 3. (0.001 0110)10 = 101.10 x? 10−5

❑ 4. (1 0110)10 = 101.10 x? 102

Binary number

1001 = 1.001 x23 1.001 = 1.125 x23, 1.125 x 8=9


100.1 = 1.001 x? 22 =1.125x4= 4.5
0.01001 = 1.001 x? 2−2 =1.125/4 = 0.28125
Floating-Point Representation (cont)
Scientific Notation
Sign, Mantissa and exponent (Mantissa means the significant digit)
Tells where the radix point is placed
0.1010 [011] 3 bits exponent to indicate the exponent
+4 2 1

Exponent 011 – we know it is a positive exponent


Exponent = 3, which means 23
Mantissa
0.1010 so we move the radix point “.” by 3 places to become
0101.0 Or = (0.5 +0 +0.125) x 23
Sign 0 Positive =(0.625)(8) = 5
Binary number becomes +0101.0 = +5.010
Floating-Point Representation (cont)
1bit Sign, 4 bits Mantissa, 3 bits exponent
Example: -ve 4 2

0.1010[010] 1.111 [0 1 0]
Exp = +2 Exp= +2
Exp +2 implies move radix point
Move the radix pt by 2 places to the right by 2 places
to the right Sign 1 Negative
0.1010 becomes 10.10 -0.111 becomes
2 1 0.5
= 2.510 -1 1. 1
= -(2 +1 +0.5)
= −3.510
End

You might also like