Unit6 Numbers
Unit6 Numbers
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 , 𝑖𝑚𝑎𝑔𝑖𝑛𝑎𝑟𝑦 𝑛𝑢𝑚𝑏𝑒𝑟
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
𝑥 𝑥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! 𝑛!
𝑥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!
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.
𝑒 𝑖𝜋 = −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).
29.625= 11101. 1 0 1 0
• . 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
+ 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
01 1 0 0 0 0 1 1 1 0 0
Pad with 0’s
If unsigned number
61C16
Hexadecimal to Binary Conversion
Example
(1 E 9 C)16
(3𝐹𝐴7)16
to
1) decimal number
2) 16 bits equivalent binary number.
Exercise: Number System
1) Convert to decimal number:
Hex 3 F A 7
↓ ↓ ↓ ↓
Bin 0011 1111 1010 0111
❑ 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
Decimal number
❑ 1. (1 0.110)10 = 101.10 x 10−1
❑ 2. (0.1 0110)10 = 101.10 x? 10−3
Binary number
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