Lecture 1-2 Number Systems
Lecture 1-2 Number Systems
Number Systems
Kyeongha Kwon
School of EE, KAIST
Decimal Numbers (I)
Represented as a set of decimal digits from 0 to 9: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Called base 10 (∵ it uses ten digits and multiplies a factor by a power of 10)
− As an example,
2
Decimal Numbers (II)
Represented by a series of coefficients: aj
− The coefficients aj are any of the 10 digits (0, 1, 2, …, 9)
− The subscript j gives the place value → aj x 10j
Why do many numbering systems use ten digits and its powers?
3
Binary Numbers (I)
Made of binary digits (bits): 0 and 1
4
Binary Numbers (II)
The first 24 numbers obtained from 2n
In computer-related works,
210 (K), 220 (M), 230 (G), 240 (T)
A binary digit (bit) is the minimum unit of binary information stored in a computer
− Groups of eight bits are called bytes: e.g. (11001001)2
6
Hexadecimal Numbers
For the base greater than 10, we use A, B, C… for digits 10, 11, 12…
An example of a hexadecimal number (base-16):
(B65F)16 = 11 x 163 + 6 x 162 + 5 x 161 + 15 x 160
= (46687)10
7
Number-base Conversions
Numbers in different bases are said to be “equivalent” if they have
the same decimal representation.
For example,
− (0011)8 = 1 x 81 + 1 x 80 = (9)10
(0011)8 and (1001)2 are equivalent!
− (1001)2 = 1 x 23 + 1 x 21 = (9)10
Decimal: Binary:
base 10 base r
8
Decimal to Base-r
If the number includes a radix point
− Separate the number into an integer part and a fraction part
(41)10 (0.6875)10
Integer part Fraction part
Decimal: Binary:
base 10 base r
9
Decimal Integer to Base-r (I)
The conversion of a decimal integer to a number in base r
− By dividing the number and all successive quotients by r and accumulating the remainders.
2 20 1
41 ÷ 2 = 20 ··· 1
2 10 0
2 5 0
∴ (41)10 = (101001)2
2 2 1
2 1 0 Decimal Binary:
0 1 Integer base r
Quotient Remainder 10
Decimal Integer to Base-r (II)
Steps:
1. Divide a decimal number by the base (e.g. 2)
Decimal Binary:
Integer base r
11
Decimal Fraction to Base-r (I)
The conversion of a decimal fraction to a number in base r
− By a method similar to that used for integers
• Multiplication is used instead of division
Terms
• Integers instead of remainders are accumulated multiplier
multiplicand product
− Example for converting (0.6875)10 to base-2
Multiplicand
Shifted-left copy of
the multiplicand
14
Binary Subtraction
Same as decimal subtraction we know
− except that the borrow in a given significant position adds 2 to a minuend digit
Binary Subtraction
1 2 borrows
0 2 2 0 0 2
1 0
0 1 1 0 1
- 1 0 1 1 1
------------------------
1 1 0 1 1 0
15
Signed Binary Numbers
For decimal numbers, plus (+) and minus (-) sign used (e.g. +25, -25)
Computers need to represent everything as binary digits (bits) : 0 or 1
Three types of signed binary number representations:
- Signed magnitude
- 1’s complement
- 2’s complement
16
Signed Magnitude
The sign with a bit placed in the leftmost position of the number,
− Making the sign bit 0 for positive and 1 for negative.
1 1 0 0 1
Sign bit Magnitude Sign bit Magnitude
0 for positive
Unsigned Binary Numbers
1 for negative 1110012 = 5710
Magnitude
17
Signed Complement
A negative number is indicated by its complement
Since positive numbers always start with 0 (plus) in the leftmost position,
the complement will always start with a 1, indicating a negative number
18
One’s Complement Representation
The 1’s complement of a binary number involves inverting all bits
+3 -3 0
- 1’s complement of 0011 is 1100 0011 + 1100 = 1111 The sum of two 1’s complement
numbers is always 1111
- 1’s complement of 0101 is 1010 0101 + 1010 = 1111
+5 -5 0
Representing zero
21
Two’s Complement Rules
For an n-bit number N, machines that use 2’s complement can represent integers
− -2n-1 ≤ N ≤ 2n-1-1, which are 2n continuous numbers.
22
Two’s Complement Addition
To add numbers represented in 2’s complement,
1. Add two numbers, including sign bits
2. Discard a carry out of the sign-bit position
1 0 1 0 0
Add + 1 1 1 0 1
-------------- Invert Plus 1
Final 1 1 0 0 0 1 (10001)2 (01110) 2 (01111) 2 = (15)10.
Result
23
Two’s Complement Subtraction
Subtraction is same as addition
− Convert subtraction into addition: +A - +B = +A + (-B)
1. Take the 2’s complement of the subtrahend, including the sign bit : B -B
0 1 1 0 0
2. Add : A + (-B)
- 0 0 0 0 1
For example, (12)10 - (1)10 = (11)10 --------------
− (12)10 = (01100)2 = (01100)2 in 2’s comp 2’s comp
0 1 1 0 0
− (1)10 = (00001)2 , (11110)2 , (11111)2 = (-1)10 Add + 1 1 1 1 1
Invert Plus 1 --------------
Final
Result 1 0 1 0 1 1
24
Two’s Complement Subtraction
Another example of a negative result, (5)10 - (12)10 = (-7)10
− (5)10 = (00101)2 in 2’s comp
− (12)10 = (01100)2 , (10011)2 (10100)2 in 2’s comp
Invert Plus 1
0 0 1 0 1
+ 1 0 1 0 0
-------------- Does this works for a negative result? Yes!
1 1 0 0 1
-7
25
Binary Codes
Digital systems use signals that have two distinct values and circuit elements
that have two stable states: 0 or 1
26
Gray Code
Many physical systems output continuous quantities
Analog information must be converted into digital form to be applied to a digital system
Gray code
− Represents digital data that have been converted from analog data.
− Only one bit changes from one decimal digit to the next
analog‐to‐digital
conversion
27
Gray Code
A binary code but not a number system
− Example of the gray code of 4-bit data
Only one bit changes from one decimal digit to the next 1-bit diff.
1-bit diff.
− Useful for reducing errors
28
ASCII Code
American Standard Code for Information Interchange
A standard binary code to represent the alphanumeric characters in binary format
7 bits
uppercase letters
128 characters
(27) lowercase letters
numerals
printable characters
29
Binary Data Storage
A binary cell
− A device that possesses two stable states and is capable of
storing one bit of information
• e.g. a SRAM cell, a DRAM cell
A resister
SRAM cell
− A group of binary cells which store any discrete quantity of
information that contains n bits
8-bit Register
31
Building a Computer (Memory + Logic)
An example of binary information processing
① The contents of two operands transferred from memory registers into R1 and R2
③
Chapters 2-6 : digital logic circuits and registers
②
Chapter 7 : memory unit
Chapter 8 : register operations at the register transfer level
32
Binary Logic
Binary logic consists of binary variables and logic operations
Binary variables
− A,B,C, x, y, z, …, taking on two possible values (1 or 0)
Logical operations
− AND, OR, NOT, …, producing a binary result (z)
x
Logical Operation z
y
33
Logical Operation: AND
Represented by a dot (·) or by the absence of an operator
− “x AND y equals to z” → “x · y = z” or “xy = z”
− z = 1 only if x = y = 1; otherwise z = 0.
Truth Table
Similar to multiplication!
z = 1 only if x = y = 1
34
Logical Operation: OR
Represented by a plus sign (+)
− “x OR y equals to z” → “x + y = z”
− z = 0 only if x = y = 0; otherwise z = 1.
Truth Table
35
Logical Operation: NOT
Represented by a prime (') or by an overbar (‾)
− “NOT x is equal to z” → “x' = z” or “x‾ = z”
− z = 0 if x = 1; z = 1 if x = 0.
Truth Table
36
Truth Table
A table of all possible combinations of the variables
− It shows the relation btw the values that the variables may take and the
result of the operation
Truth Tables
x·y=z x+ y = z x' = z
37
Logic Gates (I)
Basic building blocks of any digital system
− Electronic circuits that perform logical operations on one or more binary inputs and
produce one binary output
x
Logic Gates z
y (performing logical operations)
Symbols
39
Input-Output for Gates
Let’s draw the timing diagrams!
− Horizontal axis → time
40
Notice
HW1 will be posted on the KLMS webpage this Friday.
− Due date/time : next Friday, 11PM
− Please upload your solutions to the KLMS webpage before the due date/time
41
Need Discussion or Help?
[Mandatory] Video Lectures:
− Watch two video lectures by 11 PM this Friday.