Lec 2 3 Numbering Systems
Lec 2 3 Numbering Systems
NUMBERING SYSTEM
7
BINARY SIGNALS
• It means two-states
• 1 and 0
• True and false
• On and off
8
BYTE
9
Radix Number System
• The radix or base is the number of unique digits, including the digit zero,
used to represent numbers.
• For example, for the decimal system (the most common system in use
today) the radix is ten, because it uses the ten digits from 0 through 9.
• Base – 10 (decimal numbers)
• 0123456789
Exactly ten distinct numerals in order to represent all possible values for each
position in the number, and hence to enable us to represent all possible
integer numbers in decimal notation.
0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 values
For example, a number like "0123456789" has ten positions and each
position can contain the digits 0-9.
Each digit position has a weight associated with it.
Each digit corresponds to a power of 10 based on its position in the number
Number’s value = a weighted sum of the digits
Number’ value = digit * 10^x + digit * 10^x where x = (position number).
Example
9876 = 9x 10^3 + 8x 10^2 + 7x10^1 +6x10^0
= 9000 + 800 + 70 +6
= 9876
In the decimal system, there are 10 digits (0 through 9) which
combine to form numbers as follows:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
BINARY NUMBER
Base (radix) is 2
Two symbols: 0 and 1
Each place is weighted by the power of 2
27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
OTHER NUMBER SYSTEMS
16 symbols: { 0, 1, 2, 3, 4, 5, 6, 7,8,9 }
F. Alakeel 20
Conversion From One Radix To Another
21
Conversion from any base (radix) to decimal number
1 0 1 1
Bit 1 Bit 0
Bit 3 Bit 2
Conversion From binary to decimal
Multiply with 8 x 1 + 4 x 1 + 2 x 0 + 1x 1 = 8 + 4 + 0 + 1
these values
= 13
Conversion From binary to decimal
Example:
10112 or 1011 B
= 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20
= 8 + 0 + 2 +1
= 1110
Example:
101102 or 10110 B
1 x 24+0 x 23 + 1 x 22 + 1 x 21 + 0 x 20
= 16 + 0 + 4 +2+0
= 2210
From Octal to decimal Number
Digit 3 Digit 2
3 x 82 + 2 x 81 + 5 x 80 = 3 x 64 + 2 x 8 + 5 x 1
= 192 +16 + 5
= 213
From Octal to decimal Number
Digit 3 Digit 2
6 x 82 + 1 x 81 + 1 x 80 = 6 x 64 + 1 x 8 + 1 x 1
= 384 + 8 + 1
= 393
From Hexadecimal to decimal Number
Digit 2
D x 161 + 5 x 160 = 13 x 16 + 5 x 1
= 208 + 5
= 213
Binary Systems 31
Binary Systems 32
Binary Systems 33
Binary Systems 34
Conversion From One Radix To Another
F. Alakeel 35
Conversion from decimal to any base (radix)
165
4 0.6875 x 2 = 1 + 0.3750
23
2 0.3750 x 2 = 0 + 0.7500
3
3 0.7500 x 2 = 1 + 0.5000
0
0.5000 x 2 = 1 + 0.0000
• Repeated Division by 8
• Example
21310 = ( )8 ?
Divide-by -8 Quotient Remainder Octal digit
213 / 8 26 5 Lower digit = 5
26 / 8 3 2 Second digit =2
3/8 0 3 Third digit =3
Answer = 3258
From Decimal to octal Number
• Convert 393 to octal
Answer = 6118
From Decimal to Hexadecimal Number
• Repeated Division by 16
• Example
21310 = ( )16 ?
Divide-by -16 Quotient Remainder Hex digit
213 / 16 13 5 Lower digit = 5
13 / 16 0 13 Second digit =D
Answer = D516
Conversion From One Radix To Another
F. Alakeel 43
From base 2 to base 8 or 16 and vice verse.
44
From base 2 to base 8 or 16 and vice verse
45
SIGNED BINARY NUMBERS
Unsigned representation can be used for positive integers
How about negative integers?
Everything must be represented in binary numbers
Computers cannot use – or + signs
NOTE: For negative numbers the sign bit is always 1, and for positive numbers it
is 0 in these three systems
SIGNED MAGNITUDE
• The leftmost bit is the sign bit (0 is + and 1 is - ) and the remaining bits
hold the absolute magnitude of the number
• Examples
• -47 = 1 0 1 0 1 1 1 1
• 47 = 0 0 1 0 1 1 1 1
Two’s complement
• Find one’s complement
• Add 1
• Example (-6)
• First represent 6 in binary format (00000110)
• One’s complement (11111001)
• Two’s complement (11111010)
• Example
• 2’s complement of 10111001
• 01000110 + 1 = 01000111
• Add 1 to 1’s complement
• 2’s complement of 10100010
• 01011101 + 1 = 01011110
OPERATIONS ON UNSIGNED NUMBERS
50
OPERATIONS ON UNSIGNED NUMBERS
• EXAMPLE
+5 00000101
+11 00001011
+16 00010000
51
OPERATIONS ON UNSIGNED NUMBERS
52
OPERATIONS ON UNSIGNED NUMBERS
• EXAMPLE
53
OPERATIONS ON TWO’S COMPLEMENT
NUMBERS
Addition of two’s complement numbers
• Overflow :
• Adding two positive numbers produces a negative result
• Adding two negative numbers produces a positive result
• Note:
• Adding operands of unlike signs never produces an overflow
54
OPERATIONS ON TWO’S COMPLEMENT NUMBERS
55
OVERFLOW DETECTION
• to detect the overflow:
• If the operands have the same sign
• The result must have the same sign
• Otherwise overflow
56
ARITHMETIC ADDITION
Discard
-5 11111011 -5 11111011
+11 00001011 -11 11110101
+6 100000110 -16 111110000
Discard
SHIFT
Shift left
• Quick multiplication of unsigned numbers by powers of 2:
• Shift left n times to multiply by 2^n
• Fill in with 0’s from the right
• Overflow if the last 1 is discarded from the left
SHIFT
Shift right
• Quick division of unsigned numbers by powers of 2:
• Shift right n times to divide by 2^n
• Fill in with 0’s from the 𝑙𝑒𝑓𝑡
• Underflow if the last 1 is discarded from the right quick multiplication
OUTLINE OF COURSE
• CONTENTS GOING TO BE COVERED DURING COURSE:
• INTRODUCTION
• NUMBERING SYSTEMS
• NEGATIVE NUMBERS AND ADDING IN BINARY
• BOOLEAN ALGEBRA
• FLOW CHART, PSEUDO CODE, AND ALGORITHM
• HOW TO WRITE A C++ PROGRAM.
• INPUT AND OUTPUT
• CONDITIONS
• LOOPS
• ARRAY