Chapter 3
Chapter 3
Chapter 3
• Number Systems
• Decimal
• Binary
• Octal
• Hexadecimal
• Conversion
Decimal systems
• The decimal system
Base 10 with ten distinct digits (0, 1, 2, …, 9)
Any number greater than 9 is represented by
a combination of these digits
The weight of a digit is based on power of 10
Example:
The number 81924 is actually the sum of:
(8X104)+(1X103)+(9X102)+(2X101)+(4X100)
Binary systems
Computers use the binary system to store and
compute numbers.
Binary systems
• The binary system (0 & 1)
The two digits representation is called a binary
system
Two electrical states: on (1) & off (0)
The position weights are based on the power of 2
The various combination of the two digits
representation gives us the final value
Examples :
i) 1011011 in binary = 91 in decimal
ii) 1101.01 in binary = 13.25 in decimal
Binary Fractions
Binary fractions can also be represented:
Position Value: 2-1 2-2 2-3 2-4 2-5 etc.
Fractions: 1/2 1/4 1/8 1/16 1/32
10110012 = 8910
Exercise :
Convert the following binary numbers into their decimal
equivalent
• 11101002 = (?)10
• 101101.11012 = (?)10
Conversion of Decimal to Binary
Divide by 2 (remainder division) till the dividend is zero and
read remainders in reverse order. The right column shows
result of integer division
(mod 2) 637/2
1 318
Read answer in this 0 159
direction, Write 1 79 63710 = 1001111101 2
answer left to right 1 39
1 19
1 9
1 4
0 2
0 1 Convert 78910 to base 2
1 0
To Binary Fractions - Conversions
Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
Storage Memory Concepts
• How many bits does a computer use to store an
integer?
– Some models = 32 bits
– Other models = 64 bits
• What if we try to compute or store a larger integer?
– If we try to compute a value larger than the computer
can store, we get an arithmetic overflow error.
14
Representing Unsigned Integers
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
If we just add 1 to this number, for example, overflow will occur. We will get a wrong result.
15
Representing Signed Integers
• How does a 16 bit computer represent the value -14?
1 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
21
Two’s Complement Notation with 4-bits
Binary Pattern Value in 2’s complement.
0 1 1 1 7
0 1 1 0 6
0 1 01 5
0 1 0 0 4
0 0 1 1 3
0 0 1 0 2
0 0 0 1 1
0 0 0 0 0
1 1 1 1 -1
1 1 1 0 -2
1 1 0 1 -3
1 1 0 0 -4
1 0 1 1 -5
1 0 1 0 -6
1 0 0 1 -7
1 0 0 0 -8 22
Advantages of Two’s Complement
Notation
EXPLAIN
XXXXXXXXXXXXX Existence of two
XXXXXXXXXXXXX zeros!
Two’s-Comp Addition and Subtraction
Rules
• Starting from 1000 (-8) on up, each successive 2’s
comp number all the way to 0111 (+7) can be obtained
by adding 1 to the previous one, ignoring any carries
beyond the 4th bit position
• Since addition is just an extension of ordinary
counting, 2’s comp numbers can be added by ordinary
binary addition!
• No different cases based on operands’ signs!
• Overflow possible
Occurs if result is out of range
if operands are the same sign but sum is a different sign of
that of the operands, overflow has occurred.
Storing an integer in two’s complement format:
• Convert the integer to an n-bit binary.
• If it is positive or zero, it is stored as it is. If it is
negative, take the two’s complement and then store it.
7,425,000,000,000,000,000,000.00
The three sections are the sign (+), the shifter (21) and
the fixed-point part (7.425). Note that the shifter is the
exponent.
Some programming languages and calculators shows the
number as +7.425E21
Example:
Solution
We use the same approach as in the previous example—we
move the decimal point after the digit 2, as shown below:
The three sections are the sign (-), the shifter (-14) and
the fixed-point part (2.32). Note that the shifter is the
exponent.
Example:
Solution
We use the same idea, keeping only one digit to the left of
the radix (decimal) point.
Example:
Solution
We use the same idea, keeping only one digit to the left of
the decimal point.
Normalization
Note that the point and the bit 1 to the left of the
fixed-point section (Mantissa) are not stored; They
are implicit (hidden or not shown).
Excess Notation
The exponent (shifter), the power that shows how
many bits the decimal point should be moved to the left or
right, is a signed number.
Although this could have been stored using two’s
complement representation, a new representation, called
the Excess notation, is used instead.
In the Excess notation, both positive and negative
integers are stored as unsigned integers.
To represent a positive or negative integer, a positive
integer (called a bias) is added to each number to shift
them uniformly to the non-negative side. The value of this
bias is 2m-1 - 1, where m is the size of memory in bits to
store the exponent.
Example:
Solution
a. S = 1 (the number is negative).
b. Decimal to binary transformation: 0.0234375 =
(0.0000011)2.
c. Normalization: (0.0000011)2 = (1.1)2 × 2−6.
d. E = –6 + 127 = 121 = (01111001)2 and M = (1)2.
e. Representation:
Solution
a. The first bit represents S, the next eight bits, E and the
remaining 23 bits, M.
Single precision
0 10000010 11000000000000000000000
1.112
130 – 127 = 3
0 = positive mantissa
50
Binary Codes
• Computers also use binary numbers (integers) to
represent non-numeric information, such as text or
graphics (images).
• Binary representations of text, (letters, textual
numbers, textual symbols, etc.) are called codes.
• In a binary code, the binary number is a symbol and
does not represent an actual number.
• A code normally cannot be “operated on” in the
usual fashion – mathematical, logical, etc. That is,
one can not usually add up, for example, two binary
codes. It would be like attempting to add text and
graphics!
Character representation- ASCII
o ASCII (American Standard Code for Information
Interchange) - Binary Codes
52
Numeric and Alphabetic Codes
ASCII code
American Standard Code for Information
Interchange
an alphanumeric code
each character represented by a 7-bit code
gives 128 possible characters
codes defined for upper and lower-case alphabetic
characters, digits 0 – 9, punctuation marks and
various non-printing control characters (such as
carriage-return and backspace)
ASCII – examples
Symbol decimal Binary
7 55 00110111
8 56 00111000
9 57 00111001
: 58 00111010
; 59 00111011
< 60 00111100
= 61 00111101
> 62 00111110
? 63 00111111
@ 64 01000000
A 65 01000001
B 66 01000010
C 67 01000011
54
Representation schemes:
Top layers - Character string to character sequence:
Write each letter separately, enclosed in quotes. End
string with ‘\0’.
Notation: enclose strings in double quotes
"Hello world"
'H' 'e' 'l' 'l' 'o' ' ' 'W' 'o' 'r' 'l' 'd' '\0'
"SI"
'S' 'I' '\0'
010100110100100100000000
The colors are intended to help you read it; computers
don’t care that all the bits run together.
56
exercise
CIS110
6=2*3
Write your name in hexadecimal.
57
Unicode - representation
ASCII code can represent only 128 = 27
characters.
It only represents the English Alphabet, numeric
characters, few other characters plus some
control characters.
Unicode is designed to represent the worldwide
printable and non printable characters.
It uses 32 bits and can represent 232 characters.
For compatibility, the first 128 Unicode are the
same as that of the ASCII characters.
58
Unicode cont’d..
Let’s consider how Ethiopia’s character sets are
represented
The character set is called Ethiopic
Range: 1200-1378 (in hexadecimal)
Example character sets
59
exercise
ሀ ሁ ሂ ሃ ሄ ህ ሆ
60
Boolean Algebra & Digital Logic
62
Boolean Algebra
63
Logic Gates
64
Logic Gates
• The three simplest gates are the AND, OR, and NOT
gates.
66
Adders
Two Boolean
expressions:
sum = A B
carry = AB
Adders