Number System Operation& Code Digital System
Number System Operation& Code Digital System
Content
Decimal Number
Binary, Hexadecimal, Octal Number
Bangkok University 2
Bangkok University
Bangkok University
Summary Summary
Decimal Numbers Decimal Numbers
The position of each digit in a weighted number system is
Decimal numbers can be expressed as the sum of the
assigned a weight based on the base or radix of the products of each digit times the column value for that
system. The radix of decimal numbers is ten, because
digit. Thus, the number 9240 can be expressed as
only ten symbols (0 through 9) are used to represent any
number. (9 x 103) + (2 x 102) + (4 x 101) + (0 x 100)
The column weights of decimal numbers are or
powers of ten that increase from right to left beginning 9 x 1,000 + 2 x 100 + 4 x 10 + 0 x 1
with 100 =1: …105 104 103 102 101 100.
Express the number 480.52 as the sum of values of each
For fractional decimal numbers, the column digit.
weights are negative powers of ten that decrease from left
to right:
102 101 100. 10-1 10-2 10-3 10-4 … 480.52 = (4 x 102) + (8 x 101) + (0 x 100) + (5 x 10-1) +(2 x 10-2)
3 4
Bangkok University
Bangkok University
5 6
1
Bangkok University
Bangkok University
Summary Summary
Binary Conversions Binary Conversions
The decimal equivalent of a binary number can be
determined by adding the column values of all of the bits Convert the binary number 10010.1011 to
that are 1 and discarding all of the bits that are 0. decimal.
Start by writing the column weights; then add
Convert the binary number 100101.01 to
the weights that correspond to each 1 in the
decimal.
number.
Start by writing the column weights; then add 24 23 22 21 20. 2-1 2-2 2-3 2-4
the weights that correspond to each 1 in the 16 8 4 2 1 . 0.5 0.25 0.125 0.0625
number. 1 0 0 1 0 . 1 0 1 1
25 24 23 22 21 20. 2-1 2-2
16 +2 +0.5 +0.125 +0.0625 = 18.6875
32 16 8 4 2 1 . ½ ¼
1 0 0 1 0 1. 0 1
32 +4 +1 +¼ = 37¼
32 +4 +1 +0.25 = 37.25
7 8
Bangkok University
Bangkok University
Summary Summary
Binary Conversions Binary Conversions
You can convert a decimal whole number to binary by You can convert a decimal fraction to binary by
reversing the procedure. Write the decimal weight of repeatedly multiplying the fractional results of successive
each column and place 1’s in the columns that sum to the multiplications by 2. The carries form the binary
decimal number. number.
Convert the decimal fraction 0.1875 to binary by
Convert the decimal number 49 to binary.
repeatedly multiplying the fractional results by 2.
The column weights double in each position to 0.1875 x 2 = 0.375 carry = 0 MSB
the right. Write down column weights until the 0.3750 x 2 = 0.750 carry = 0
last number is larger than the one you want to 0.7500 x 2 = 1.500 carry = 1
convert. 0.5000 x 2 = 1.000 carry = 1
26 25 24 23 22 21 20. Stop
64 32 16 8 4 2 1.
0 1 1 0 0 0 1. Answer = .0011 (for five significant digits)
9 10
Bangkok University
Bangkok University
Summary Checkup1
Binary Conversions Convert the following decimal numbers to binary
19
You can convert decimal to any other base by repeatedly
45
dividing by the base. For binary, repeatedly divide by 2:
5.3125 See Solution in Page 53-54
Convert the decimal number 49 to binary by Convert the following binary to decimal number
repeatedly dividing by 2.
1101101
You can do this by “reverse division” and the
0.1011 See Solution in Page 50-51
answer will read from left to right. Put
110.11
11 12
2
Bangkok University
Bangkok University
Summary Summary
Decimal Hexadecimal Binary Decimal Hexadecimal Binary
Hexadecimal Numbers 0 0 0000 Hexadecimal Numbers 0 0 0000
1 1 0001 1 1 0001
Hexadecimal uses sixteen characters 2 2 0010 Hexadecimal is a weighted number 2 2 0010
to represent numbers: the numbers 0 3 3 0011 system. The column weights are 3 3 0011
through 9 and the alphabetic 4 4 0100 powers of 16, which increase from 4 4 0100
characters A through F. 5 5 0101 5 5 0101
6 6 0110
right to left. 6 6 0110
Large binary number can 7 7 0111 7 7 0111
easily be converted to hexadecimal 8 8 1000
Column weights { 4096
3 2 1
16 16 16 16 .
256 16 1 .
0
8 8 1000
by grouping bits 4 at a time and 9 9 1001 9 9 1001
10 A 1010 Express 1A2F16 in decimal. 10 A 1010
writing the equivalent hexadecimal
11 B 1011 11 B 1011
character. 12 C 1100
Start by writing the column weights:
12 C 1100
Express 1001 0110 0000 11102 in 4096 256 16 1
13 D 1101 13 D 1101
hexadecimal: 1 A 2 F16
14 E 1110 14 E 1110
Group the binary number by 4- 15 F 1111 1(4096) + 10(256) +2(16) +15(1) = 670310 15 F 1111
bits starting from the right. Thus,
960E 13 14
Bangkok University
Bangkok University
Checkup2 Summary
Decimal Octal Binary
Convert the following decimal numbers to hexadecimal number Octal Numbers 0 0 0000
65010 See Solution in Page 76 1 1 0001
Octal uses eight characters the 2 2 0010
2606.101562510 See Solution in Page ๖
numbers 0 through 7 to represent 3 3 0011
Convert the following hexadecimal numbers to decimal number
numbers. There is no 8 or 9 4 4 0100
E516 See Solution in Page 75 5 5 0101
character in octal.
D3C.2F16 See Solution in Page ๙ 6 6 0110
Binary number can easily be
Convert the following hexadecinal numbers to binary number 7 7 0111
converted to octal by grouping bits 3 8 10 1000
10A416 at a time and writing the equivalent 9 11 1001
CF8E16 See Solution in Page 74 octal character for each group. 10 12 1010
A69.23816 See Solution in Page ๑๓ 11 13 1011
Convert the following binary numbers to octal number Express 1 001 011 000 001 1102 in 12 14 1100
1001012 octal: 13 15 1101
14 16 1110
11001010010101112 See Solution in Page 74 Group the binary number by 3-bits
15 17 1111
11111100001101.1000112 See Solution in Page ๑๓ starting from the right. Thus,
1130168
15 16
Bangkok University
Bangkok University
Summary Checkup3
Decimal Octal Binary
Octal Numbers 0 0 0000 Convert the following decimal numbers to octal number
1 1 0001
359 See Solution in Page 80
Octal is also a weighted number 2 2 0010
415.65625 See Solution in Page ๕
system. The column weights are 3 3 0011 Convert the following octal numbers to decimal number
powers of 8, which increase from 4 4 0100
2374 See Solution in Page 80
5 5 0101
right to left.
15.21
6 6 0110
Convert the following octal numbers to binary number
7 7 0111
{
83 82 81 80 .
Column weights 512 64 8 1 . 8 10 1000
25
9 11 1001
7526 See Solution in Page 81
Express 37028 in decimal. 10 12 1010
524.61 See Solution in Page ๑๑
11 13 1011 Convert the following binary numbers to octal number
Start by writing the column weights:
12 14 1100
100101
512 64 8 1
13 15 1101
101111001 See Solution in Page 82
3 7 0 28
14 16 1110
11101001000.01011 See Solution in Page ๑๑
3(512) + 7(64) +0(8) +2(1) = 198610 15 17 1111
17 18
3
Bangkok University
Bangkok University
Summary Summary
Binary Addition Binary Addition
The rules for binary addition are Add the binary numbers 00111 and 10101 and
0+0=0 Sum = 0, carry = 0 show the equivalent decimal addition.
0+1=0 Sum = 1, carry = 0 0111
1+0=0 Sum = 1, carry = 0 00111 7
1 + 1 = 10 Sum = 0, carry = 1
10101 21
When an input carry = 1 due to a previous result, the
rules are 11100 = 28
1 + 0 + 0 = 01 Sum = 1, carry = 0
1 + 0 + 1 = 10 Sum = 0, carry = 1
1 + 1 + 0 = 10 Sum = 0, carry = 1
1 + 1 + 1 = 10 Sum = 1, carry = 1
19 20
Bangkok University
Bangkok University
Summary Summary
Hexadecimal Addition Octal Addition
Add the hexadecimal numbers DF16 and AC16 Add the octal numbers 3758 and 4218 and show
and show the equivalent decimal addition. the equivalent decimal addition.
1 1
DF 223 375 253 Î 3(64)+7(8)+5
AC 172 421 273 Î 4(64)+2(8)+1
18 B = 395 Î 1(256) +8(16) + 11 1016 = 526 Î 1(512) +1(8) +6
Bangkok University
Checkup4 Summary
Add the following numbers Binary Subtraction
738 + 1258 The rules for binary subtraction are
635.428 + 345.768 0−0=0
235A16 + 3B7116
1−1=0
1−0=1
738B.2A16 +91CD.E416 10 − 1 = 1 with a borrow of 1
10112 + 11102 Subtract the binary number 00111 from 10101
1010111.10112 +1011011.102 and show the equivalent decimal subtraction.
111
10101
/ / / 21
00111 7
01110 = 14
23 24
4
Bangkok University
Bangkok University
Summary Summary
1’s Complement 2’s Complement
The 1’s complement of a binary number is just the The 2’s complement of a binary number is found by
inverse of the digits. To form the 1’s complement, adding 1 to the LSB of the 1’s complement.
change all 0’s to 1’s and all 1’s to 0’s. Recall that the 1’s complement of 11001010 is
For example, the 1’s complement of 11001010 00110101 (1’s complement)
is 00110101 To form the 2’s complement, add 1: +1
00110110 (2’s complement)
In digital circuits, the 1’s complement is formed by
1 1 0 0 1 0 1 0
using inverters:
1 1 0 0 1 0 1 0
1
0 0 1 1 0 1 0 1
Input bits
Carry
Adder
0 0 1 1 0 1 0 1 in (add 1)
Output bits (sum)
0 0 1 1 0 1 1 0
25 26
Bangkok University
Bangkok University
Summary Summary
Binary Subtraction By 1’s Complement Binary Subtraction By 1’s Complement
The rules for binary subtraction are If have carry ,add with LSB. Result is positive number
1’s complement subtracted No carry, using 1’s complement. The result is negative number
Adding between two number
If have carry ,add with LSB. Result is positive number Subtract the binary number 00111 from 10101 and
No carry, using 1’s complement. The result is negative number show the equivalent decimal subtraction.
Subtract the binary number 10101 from 00111 and 10101 21
show the equivalent decimal subtraction. 00111 =1’s 11000 7
00111 7 1 01101
10101 =1’s 01010 21 add with carry 1Î 01110 = 14 positive
0 10001
1’s 01110 = 14 negative Î-14
27 28
Bangkok University
Bangkok University
Summary Summary
Binary Subtraction By 2’s Complement Binary Subtraction By 2’s Complement
The rules for binary subtraction are If have carry ,add with LSB. Result is positive number
2’s complement subtracted No carry, using 1’s complement. The result is negative number
Adding between two number
If have carry ,discard carry. Result is positive number Subtract the binary number 00111 from 10101 and
No carry, using 2’s complement. The result is negative number show the equivalent decimal subtraction.
Subtract the binary number 10101 from 00111 and 10101 21
show the equivalent decimal subtraction. 00111 =2’s 11001 7
00111 7 1 01110
10101 =2’s 01011 21 discard carry 1 Î 01110 = 14 positive
0 10010
2’s 01110 = 14 negative Î-14
29 30
5
Bangkok University
Bangkok University
Checkup5 Summary
Signed Binary Numbers
Binary Subtraction with 1’s complement
1011012 – 1001112 There are several ways to represent signed binary
11002 – 1011012 numbers. In all cases, the MSB in a signed number is the
1101102– 1010012 sign bit, that tells you if the number is positive or
Binary Subtraction with 2’s complement negative.
1011102 – 1001112 Computers use a modified 2’s complement for
110012 – 1011012 signed numbers. Positive numbers are stored in true
1001102– 1010012 form (with a 0 for the sign bit) and negative numbers
are stored in complement form (with a 1 for the sign bit).
For example, the positive number 58 is written using 8-bits as
00111010 (true form).
31 32
Bangkok University
Bangkok University
Summary Summary
Signed Binary Numbers Floating Point Numbers
Negative numbers are written as the 2’s complement of Floating point notation is capable of representing
the corresponding positive number. very large or small numbers by using a form of
The negative number −58 is written as: scientific notation. A 32-bit single precision number
−58 = 11000110 (complement form) is illustrated.
Sign bit Magnitude S E (8 bits) F (23 bits)
bits Sign bit Biased exponent (+127) Magnitude with MSB dropped
An easy way to read a signed number that uses this notation is
to assign the sign bit a column weight of −128 (for an 8-bit
number). Then add the column weights for the 1’s. Express the speed of light, c, in single precision floating
Assuming that the sign bit = −128, show that 11000110 = − point notation. (c = 0.2998 x 109)
58 as a 2’s complement signed number: In binary, c = 0001 001 1101 1110 1001 0101 1100 00002.
Column weights: −128 64 32 16 8 4 2 1. In scientific notation, c = 1.001 1101 1110 1001 0101 1100 0000 x 228.
1 1 0 0 0 1 1 0 S = 0 because the number is positive. E = 28 + 127 = 15510 = 1001 10112.
−128 +64 +4 +2 = −58 F is the next 23 bits after the first 1 is dropped.
In floating point notation, c = 0 10011011 001 1101 1110 1001 0101 1100
33 34
Bangkok University
Bangkok University
Summary Summary
Arithmetic Operations with Signed Numbers Arithmetic Operations with Signed Numbers
Using the signed number notation with negative Rules for subtraction: 2’s complement the subtrahend and
numbers in 2’s complement form simplifies addition add the numbers. Discard any final carries. The result is in
and subtraction of signed numbers. signed form.
Rules for addition: Add the two signed numbers. Discard Repeat the examples done previously, but subtract:
any final carries. The result is in signed form. 00011110 (+30) 00001110 (+14) 11111111 (−1)
Examples: − 00001111 –(+15) − 11101111 –(−17) − 11111000 –(−8)
00011110 = +30 00001110 = +14 11111111 = −1 2’s complement subtrahend and add:
00001111 = +15 11101111 = −17 11111000 = −8 00011110 = +30 00001110 = +14 11111111 = −1
00101101 = +45 11111101 = −3 1 11110111 = −9 11110001 = −15 00010001 = +17 00001000 = +8
Discard carry 1 00001111 = +15 00011111 = +31 1 00000111 = +7
Discard carry Discard carry
35 36
6
Bangkok University
Bangkok University
Summary Summary
Decimal Binary BCD
BCD 0 0000 0000 BCD
1 0001 0001
Binary coded decimal (BCD) is a 2 0010 0010 You can think of BCD in terms of column weights in
weighted code that is commonly 3 0011 0011 groups of four bits. For an 8-bit BCD number, the
used in digital systems when it is 4 0100 0100 column weights are: 80 40 20 10 8 4 2 1.
5 0101 0101
necessary to show decimal 6 0110 0110 What are the column weights for the BCD
numbers such as in clock 7 0111 0111 number 1000 0011 0101 1001?
displays. 8 1000 1000
The table illustrates the 9 1001 1001
difference between straight binary 10 1010 0001 0000 8000 4000 2000 1000 800 400 200 100 80 40 20 10 8 4 2 1
and BCD. BCD represents each 11 1011 0001 0001
decimal digit with a 4-bit code. Notice Note that you could add the column weights where there
12 1100 0001 0010
that the codes 1010 through 1111 are is a 1 to obtain the decimal number. For this case:
13 1101 0001 0011
not used in BCD. 14 1110 0001 0100 8000 + 200 +100 + 40 + 10 + 8 +1 = 835910
15 1111 0001 0101
37 38
Bangkok University
Bangkok University
Summary Summary
Decimal Binary Gray code
BCD Gray code 0 0000 0000
A lab experiment in which BCD 1 0001 0001
is converted to decimal is shown. Gray code is an unweighted code 2 0010 0011
that has a single bit change 3 0011 0010
between one code word and the 4 0100 0110
5 0101 0111
next in a sequence. Gray code is 6 0110 0101
used to avoid problems in systems 7 0111 0100
where an error can occur if more 8 1000 1100
than one bit changes at a time. 9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
39 40
Bangkok University
Bangkok University
Summary Summary
Gray code ASCII
7
Bangkok University
Bangkok University
Summary Summary
Parity Method Cyclic Redundancy Check
The parity method is a method of error detection for The cyclic redundancy check (CRC) is an error detection
simple transmission errors involving one bit (or an method that can detect multiple errors in larger blocks of data.
odd number of bits). A parity bit is an “extra” bit At the sending end, a checksum is appended to a block of data.
attached to a group of bits to force the number of 1’s At the receiving end, the check sum is generated and
compared to the sent checksum. If the check sums are the same,
to be either even (even parity) or odd (odd parity).
no error is detected.
The ASCII character for “a” is 1100001 and for “A” is
1000001. What is the correct bit to append to make both
of these have odd parity?
The ASCII “a” has an odd number of bits that are equal
to 1; therefore the parity bit is 0. The ASCII “A” has an
even number of bits that are equal to 1; therefore the
parity bit is 1.
43 44
Bangkok University
Bangkok University
Selected Key Terms Selected Key Terms
Byte A group of eight bits Alphanumeric Consisting of numerals, letters, and other
characters
Floating-point A number representation based on scientific
number notation in which the number consists of an ASCII American Standard Code for Information
exponent and a mantissa. Interchange; the most widely used alphanumeric
code.
Hexadecimal A number system with a base of 16.
Parity In relation to binary codes, the condition of
Octal A number system with a base of 8.
evenness or oddness in the number of 1s in a code
BCD Binary coded decimal; a digital code in which each group.
of the decimal digits, 0 through 9, is represented by
Cyclic A type of error detection code.
a group of four bits.
redundancy
check (CRC)
45 46
Bangkok University
Bangkok University
1. For the binary number 1000, the weight of the column 2. The 2’s complement of 1000 is
with the 1 is
a. 0111
a. 4
b. 1000
b. 6
c. 1001
c. 8
d. 1010
d. 10
47
© 2008 Pearson Education 48
© 2008 Pearson Education
8
Bangkok University
Bangkok University
4. The hexadecimal number 2C has a decimal equivalent 7. The number 1010 in BCD is
value of
a. equal to decimal eight
a. 14
b. equal to decimal ten
b. 44
c. equal to decimal twelve
c. 64
d. invalid
d. none of the above
49
© 2008 Pearson Education 50
© 2008 Pearson Education
Bangkok University
Bangkok University
9. An example of an alphanumeric code is
Answers:
a. hexadecimal 7. d
1. c
b. ASCII 9. b
2. b
c. BCD 4. b
d. CRC
51
© 2008 Pearson Education 52
Bangkok University
?? Question ??
53