Transcript decimal

Ch2 Number systems and codes
Octal(base 8)
Decimal(base 10)
Binary(base 2)
Hexadecimal
(base16)
[email protected]
1
Examples
• Decimal numbers(base 10)
 36.210
9810
• Hexadecimal number(base 16)
 3F216
• Binary number(base 2)
 10112
2
Positional system
• Each digit carries a certain weight based on its
position.
 346.17463.71 Position matters
 Weight vs Position
3
Decimal Positional System
(Base 10 or radix 10)
decimal point
…
104
103
102
101
100
.
10-1
10-2
…
tenths position
ones position
tens position
hundredth position
hundreds position
4
Binary Positional System
(Base 2 or radix 2)
binary point
…
24
23
22
21
20
.
2-1
2-2
…
halves position
ones position
twos position
quarters position
fours position
5
Example
Decimal Example
346.1710  (3 10 2 )  (4 101 )  (6 100 )  (110 1 )  (7 10 2 )
 300
 40
 6
 0.1
 0.07
Binary Example
1101.012  1 23  1 2 2  0  21  1 20  0  2 1  1 2 2
 8  4
 13.2510
0
1
 0
 .25
6
Binary to Decimal Conversion
• What is 1101012 in decimal?
1101012  1 25  1 2 4  0  23  1 2 2  0  21  1 20
 32  16
 5310
 0
 4
 0
1
7
n
2n
n
2n
0
20=1
8
28=256
1
21=1
9
29=512
2
22=4
10
210=1024
3
23=8
11
211=2048
4
24=16
12
212=4096
5
25=32
20
220=1M
6
26=64
30
230=1G
7
27=128
8
Decimal-To-Binary
Conversions(method 1)
• The decimal number is simply expressed as a sum of
powers of 2, and then 1s and 0s are written in the
appropriate bit positions.
5010  32  18
 32  16  2
 1 25  1 2 4  1 21
5010  110010 2
34610  256  90
 256  64  26
 256  64  16  10
 256  64  16  8  2
 1 28  1 26  1 2 4  1 23  1 21
34610  1010110102
9
(Method 2)Flowchart for Repeated Division
10
Example for Repeated Division
quotient
remainder
50/2 =
25
0
25/2 =
12
1
12/2 =
6
0
6/2 =
3
0
3/2 =
1
1
1/2
0
1
=
LSB
MSB
5010=1100102
11
Example for Repeated Division
quotient
remainder
346/2
173
0
173/2
86
1
86/2
43
0
43/2
21
1
21/2
10
1
10/2
5
0
5/2
2
1
2/2
1
0
1/2
0
1
34610=1010110102
12
How many different values can we represent with N binary
digits? Decimal digits? Octal digits? Radix Z digits?
•Decimal: 1 digit
0-9
2 digits
10X10=100 different values
106=1,000,000 different values
.. 6 digits
•Binary: 1 digit
2 digits
10 different values
0,1
2 different values=21
00,01,10,11 4 different values=22
n digits
•Radix Z digits: n digits
2n different values
Zn different values(0 thru. Zn-1)
13
Octal-to-Decimal Conversion
• Octal-to-Decimal Conversion
372  3  (82 )  7  (81)  2  (80 )
8
 3  64  7  8  2 1
 250
10
24.6  2  (81)  4  (80 )  6  (8 1)
8
 20.75
10
14
Decimal-to-Octal Conversion
• Convert 26610 to Octal
quotient
remainder
266/8 =
33
2
33/8 =
4
1
4/8
0
4
=
LSB
MSB
26610=4128
15
Octal-to-Binary Conversion
• Convert 4728 to binary
4
7
2



100
111
010
• Convert 54318 to binary
5
4
3
1




101
100
011
001
16
Binary-to-Octal Conversion
• Convert 1001110102 to octal
1 0 0 1 1 1 0 1 0


  





4
7
28
• Convert 110101102 to octal
0 1 1 0 1 0 1 1 0
 

 


3
2

68
17
Octal-to-hex Conversion
• Convert B2F16 to octal
B2F16=1011 0010 1111 {convert to binary}
=101 100 101 111 {group into three-bit
= 5
4
5
78
groupings}
{Convert to octal}
18
2-5 BCD Code
• If each digit of a decimal number is represented by
its binary equivalent, the result is a code called
binary-code-decimal(BCD).
8
7
4
(decimal)



1000
0111
0100
9
4
3



1001
0100
0011
(BCD)
(decimal)
(BCD)
19
Example
• Convert 0110100000111001(BCD) to its decimal
equivalent.
• Convert the BCD number 011111000001 to its decimal
equivalent.
20
Comparison of BCD and Binary
• A straight binary code takes the complete decimal
number and represents it in binary.
• A BCD code converts each decimal digit to binary
individually.
13710=100010012
13710=0001 0011 0111
(binary)
(BCD)
• BCD uses more bits, easier to convert to and from
decimal.
21
Review Questions
• Represent the decimal value 178 by its straight
binary equivalent. Then encode the same decimal
number using BCD.
• How many bits are required to represent an eightdigit decimal number in BCD?
• What is an advantage of encoding a decimal number in
BCD as compared with straight binary? What is a
disadvantage?
22
2-6 Putting it ALL together(TBA)
23
2-7 The byte
• A string of 8 bits is called a byte.
• How many bytes are in a 32-bit string?
• What is the largest decimal value that can be
represented in binary using two bytes?
• How many bytes are needed to represent the decimal
value 846,569 in BCD?
24
Review Questions
• How many bytes are needed to represent 23510 in
binary?
• What is the largest decimal value that can be
represented in BCD using two bytes?
25
2-8 Alphanumeric Codes
• Codes representing letters of the alphabet,
punctuation marks, and other special characters as
well as numbers are called alphanumeric codes.
• The most widely used alphanumeric code is the
American Standard Code for Information
Interchange(ASCII). The ASCII(pronounced “askee”)
code is a seven-bit code.
26
Partial listing of ASCII code
27
Example
• The following is a message encoded in ASCII code.
What is the message?
1001000 1000101 1001100 1010000
• An operator is typing in a JAVA program at the
keyboard of a certain microcomputer. The computer
converts each keystroke into its ASCII code and
stores the code as a byte in memory. Determine the
binary strings that will be entered into memory when
the operator types in the following JAVA statement.
import java.applet.*
28
Review Questions
• Encode the following message in ASCII code using the
hex representation: “COST=$72.”
• The following padded ASCII-coded message is stored in
successive memory location in a computer:
01010011 01010100 01001111 01010000
What is the message?
29
2-9 Parity method for error
detection
Whenever information is transmitted from one device to another device, there is
a possibility that errors can occur such that the receiver does not receive the
identical information that was sent by the transmitter.
30
Parity Bit
•
•
•
•
A parity bit is an extra bit that is attached to a code
group that is being transferred from one location to
another.
Even-parity
– The value of the parity bit is chosen so that the total
number of 1s in the code group(including the parity bit)
is an even number.
1 1 0 0 0 0 1 1

Added parity bit
Odd-parity
– The parity bit is chosen so that the total number of
1s(including the parity bit) is an odd number.
The parity bit is issued to detect any single-bit errors
during the transmission of a code from one location to
another.
31
Example
• Computers often communicate with other remote
computers over the telephone lines. For example, this
is how some communication over the internet takes
place. When one computer is transmitting a message to
another, the information is usually encoded in
ASCII.What actual bit strings would a computer
transmit to send the message HELLO, using ASCII with
even parity?
32
Review Questions
• Attach an odd-parity bit to the ASCII code for the
$ symbol, and express the result in hexadecimal.
• Attach an even-parity bit to the BCD code for decimal
69.
• Why can’t the parity method detect a double error in
transmitted data?
33
2-10 Applications
• A typical CD-ROM can store 650 megabytes of digital
data. Since mega=220, how many bits of data can a CDROM hold?
• An automotive parts shop uses a computer to store all
of its parts numbers in 7-bit ASCII code with an odd
parity bit. The codes for each part are stored in
successive memory locations. List the binary contents
of memory that stores the part number JR2-5.
• A small process-control computer uses octal codes to
represent its 12-bit memory addresses.
– How many octal digits are required?
– What is the range of addresses in octal?
– How many memory locations are there?
34
Applications(cont.)
• A typical PC uses a 20-bit address code for its
memory locations.
– How many hex digits are needed to represent a
memory address?
– What is the range of addresses?
– What is the total number of memory locations?
• Most calculators use BCD to store the decimal values
as they are entered into the keyboard and to drive
the digit displays.
– If a calculator is designed to handle 8-digit
decimal numbers, how many bits does this require?
– What bits are stored when the number 375 is
entered into the calculator?
35
Summary
• The octal and hexadecimal number systems are used in
digital systems and computers as efficient ways of
representing binary quantities.
• In conversion between octal and binary, one octal
digit corresponds to three bits. In conversions
between hex and binary, each hex digit corresponds to
four bits.
• The repeated-division method is used to convert
decimal numbers to binary, octal or hexadecimal.
• Using an N-bit binary number, we can represent
decimal values from 0 to 2N-1.
• The BCD code for a decimal number is formed by
converting each digit of the decimal number to its
four-bit binary equivalent.
36
Summary(cont.)
• A byte is a string of eight bits.
• An alphanumeric code is one that uses groups of bits
to represent all of the various characters and
functions that are part of a typical computer’s
keyboard. The ASCII code is the most widely used
alphanumeric code.
• The parity method for error detection attaches a
special parity bit to each transmitted group of bits.
37