Download presentation
1
Ch2 Number systems and codes
Octal(base 8) Decimal(base 10) Binary(base 2) Hexadecimal (base16)
2
Examples Decimal numbers(base 10) 36.210 9810
Hexadecimal number(base 16) 3F216 Binary number(base 2) 10112
3
Positional system Each digit carries a certain weight based on its position. 346.17 Position matters Weight vs Position
4
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
5
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
6
Example Decimal Example Binary Example
7
Binary to Decimal Conversion
What is in decimal?
8
n 2n 20=1 1 21=1 2 22=4 3 23=8 4 24=16 5 25=32 6 26=64 7 27=128 n 2n 8 28=256 9 29=512 10 210=1024 11 211=2048 12 212=4096 20 220=1M 30 230=1G
9
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.
10
(Method 2)Flowchart for Repeated Division
11
Example for Repeated Division
quotient remainder 50/2 = LSB 25/2 = 12/2 = 6/2 = 3/2 = 1/2 = MSB 5010=
12
Example for Repeated Division
quotient remainder 346/ 173/ 86/ 43/ 21/ 10/ 5/ 2/ 1/ 34610=
13
How many different values can we represent with N binary digits
How many different values can we represent with N binary digits? Decimal digits? Octal digits? Radix Z digits? Decimal: 1 digit different values 2 digits X10=100 different values .. 6 digits =1,000,000 different values Binary: 1 digit , different values=21 2 digits ,01,10,11 4 different values=22 n digits 2n different values Radix Z digits: n digits Zn different values(0 thru. Zn-1)
14
Octal-to-Decimal Conversion
15
Decimal-to-Octal Conversion
Convert to Octal quotient remainder 266/8 = LSB 33/8 = 4/8 = MSB 26610=4128
16
Octal-to-Binary Conversion
Convert 4728 to binary 4 7 2 Convert to binary
17
Binary-to-Octal Conversion
Convert to octal Convert to octal
18
Octal-to-hex Conversion
Convert B2F16 to octal B2F16= {convert to binary} = {group into three-bit groupings} = {Convert to octal}
19
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). (decimal) (BCD) (decimal) (BCD)
20
Example Convert 0110100000111001(BCD) to its decimal equivalent.
Convert the BCD number to its decimal equivalent.
21
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= (binary) 13710= (BCD) BCD uses more bits, easier to convert to and from decimal.
22
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 eight-digit decimal number in BCD? What is an advantage of encoding a decimal number in BCD as compared with straight binary? What is a disadvantage?
23
2-6 Putting it ALL together(TBA)
24
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?
25
Review Questions How many bytes are needed to represent in binary? What is the largest decimal value that can be represented in BCD using two bytes?
26
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.
27
Partial listing of ASCII code
28
Example The following is a message encoded in ASCII code. What is the message? 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.*
29
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: What is the message?
30
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.
31
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. 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.
32
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?
33
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?
34
2-10 Applications A typical CD-ROM can store 650 megabytes of digital data. Since mega=220, how many bits of data can a CD-ROM 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?
35
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?
36
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.
37
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.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.