0% found this document useful (0 votes)
13 views

Programming Fundamentals Loops

The document discusses number systems and codes. It covers topics like positional notation, different number system bases, conversion between number systems, and representation of negative numbers. It also discusses binary, octal, hexadecimal number systems and conversion to decimal.

Uploaded by

Abubaker Saeed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Programming Fundamentals Loops

The document discusses number systems and codes. It covers topics like positional notation, different number system bases, conversion between number systems, and representation of negative numbers. It also discusses binary, octal, hexadecimal number systems and conversion to decimal.

Uploaded by

Abubaker Saeed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Digital Logic and Design

Number Systems & Codes

Instructor : Waseem Abbas


Department of Computer Science
GCUF Chiniot Campus
Number Systems & Codes
Number Systems
▪ Information Representations
▪ Positional Notations
▪ Decimal (base 10) Number System
▪ Other Number Systems &
Base-R to Decimal Conversion
▪ Decimal-to-Binary Conversion
❖ Sum-of-Weights Method
❖ Repeated Division-by-2 Method (for whole numbers)
❖ Repeated Multiplication-by-2 Method (for fractions)
Number Systems & Codes

▪ Conversion between Decimal and other Bases


▪ Conversion between Bases
▪ Binary-Octal/Hexadecimal Conversion
▪ Binary Arithmetic Operations
▪ Negative Numbers Representation
❖ Sign-and-magtitude
❖ 1s Complement
❖ 2s Complement

▪ Comparison of Sign-and-Magnitude and


Complements
Number Systems & Codes
▪ Complements
❖ Diminished-Radix Complements
❖ Radix Complements

▪ 2s Complement Addition and Subtraction


▪ 1s Complement Addition and Subtraction
▪ Overflow
▪ Fixed-Point Numbers
▪ Floating-Point Numbers
▪ Arithmetics with Floating-Point Numbers
Number Systems & Codes

Codes
▪ Binary Coded Decimal (BCD)
▪ Gray Code
❖ Binary-to-Gray Conversion
❖ Gray-to-Binary Conversion

▪ Other Decimal Codes


▪ Self-Complementing Codes
▪ Alphanumeric Codes
▪ Error Detection Codes
Information Representation
▪ Numbers are important to computers
❖ represent information precisely
❖ can be processed

▪ For example:
❖ to represent yes or no: use 0 for no and 1 for yes
❖ to represent 4 seasons: 0 (autumn), 1 (winter), 2(spring) and
3 (summer)
❖ NRIC number: a letter, 7 digits, and a check code
❖ matriculation number (8 alphanumeric) to represent
individual students
Information Representation
▪ Elementary storage units inside computer are
electronic switches. Each switch holds one of two
states: on (1) or off (0).

ON OFF

▪ We use a bit (binary digit), 0 or 1, to represent the


state.
Information Representation
▪ Storage units can be grouped together to cater for
larger range of numbers. Example: 2 switches to
represent 4 values.

0 (00)
1 (01)
2 (10)
3 (11)
Information Representation
▪ In general, N bits can represent 2N different values.
▪ For M values, log 2 M  bits are needed.
1 bit → represents up to 2 values (0 or 1)
2 bits → rep. up to 4 values (00, 01, 10 or 11)
3 bits → rep. up to 8 values (000, 001, 010. …, 110, 111)
4 bits → rep. up to 16 values (0000, 0001, 0010, …, 1111)
32 values → requires 5 bits
64 values → requires 6 bits
1024 values → requires 10 bits
40 values → requires 6 bits
100 values → requires 7 bits
Positional Notations
▪ Position-independent notation
❖ each symbol denotes a value independent of its position:
Egyptian number system

▪ Relative-position notation
❖ Roman numerals symbols with different values: I (1), V (5),
X (10), C (50), M (100)
❖ Examples: I, II, III, IV, VI, VI, VII, VIII, IX
❖ Relative position important: IV = 4 but VI = 6

▪ Computations are difficult with the above two


notations
Positional Notations
▪ Weighted-positional notation
❖ Decimal number system, symbols = { 0, 1, 2, 3, …, 9 }
❖ Position is important
❖ Example:(7594)10 = (7x103) + (5x102) + (9x101) + (4x100)
❖ The value of each symbol is dependent on its type and its
position in the number
❖ In general, (anan-1… a0)10 = (an x 10n) + (an-1 x 10n-1) + … +
(a0 x 100)
Positional Notations
▪ Fractions are written in decimal numbers after the
decimal point.
❖ 2 3 4 = (2.75)10 = (2 x 100) + (7 x 10-1) + (5 x 10-2)
❖ In general, (anan-1… a0 . f1f2 … fm)10 = (an x 10n) + (an-1x10n-
1) + … + (a0 x 100) + (f1 x 10-1) + (f2 x 10-2) + … + (fm x 10-m)

▪ The radix (or base) of the number system is the total


number of digits allowed in the system.
Decimal (base 10) Number System

▪ Weighting factors (or weights) are in powers-of-10:


… 103 102 101 100.10-1 10-2 10-3 10-4 …
▪ To evaluate the decimal number 593.68, the digit in
each position is multiplied by the corresponding
weight:
5102 + 9101 + 3100 + 610-1 + 810-2
= (593.68)10
Other Number Systems &
Base-R to Decimal Conversion
▪ Binary (base 2): weights in powers-of-2.
– Binary digits (bits): 0,1.

▪ Octal (base 8): weights in powers-of-8.


– Octal digits: 0,1,2,3,4,5,6,7.

▪ Hexadecimal (base 16): weights in powers-of-16.


– Hexadecimal digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

▪ Base R: weights in powers-of-R.


Other Number Systems &
Base-R to Decimal Conversion
▪ (1101.101)2 = 123 + 122 + 120 + 12-1 + 12-3
= 8 + 4 + 1 + 0.5 + 0.125 = (13.625)10
▪ (572.6)8 = 582 + 781 + 280 + 68-1
= 320 + 56 + 2 + 0.75 = (378.75)10
▪ (2A.8)16 = 2161 + 10160 + 816-1
= 32 + 10 + 0.5 = (42.5)10
▪ (341.24)5 = 352 + 451 + 150 + 25-1 + 45-2
= 75 + 20 + 1 + 0.4 + 0.16 = (96.56)10
Other Number Systems &
Base-R to Decimal Conversion
▪ Counting in Binary Decimal
Number
Binary
Number
▪ Assuming non-negative values, 0
1
0
0
0
0
0
0
0
1
n bits → largest value 2n – 1. 2
3
0
0
0
0
1
1
0
1
Examples: 4 bits → 0 to 15; 4 0 1 0 0
5 0 1 0 1
6 bits → 0 to 63. 6 0 1 1 0
7 0 1 1 1
▪ range of m values → log2m bits 8 1 0 0 0
9 1 0 0 1
10 1 0 1 0
11 1 0 1 1
12 1 1 0 0
13 1 1 0 1
14 1 1 1 0
15 1 1 1 1
Solve it yourself (Exercise 1.1)
1. The binary number 1011011 is equal to the decimal number
a. 63 b. 91 c. 92 d. 139
2. Which of the following has the largest value?
a. (110)10 b. (10011011)2 c. (1111)5 d. (9A)16 e. (222)8
3. What is the weight of the digit ‘3’ in the base-7 number 12345?
a. 3 b. 5 c. 7 d. 14 e. 49
4. If (321)4 = (57)10, what is the decimal equivalent of (32100000)4?
a. 57  105 b. 57  104 c. 57  45 d. 57  410
e. This is too difficult.
End of segment

You might also like