Upload
feo
View
78
Download
0
Embed Size (px)
DESCRIPTION
3. Number Systems and Codes. Objectives. Explain the decimal number system. Explain integer numbers, fractional numbers, and real numbers. Describe the binary number system. Convert decimal numbers to binary and vice versa. - PowerPoint PPT Presentation
Citation preview
Chapter
3Number Systems and
Codes
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Objectives
• Explain the decimal number system.• Explain integer numbers, fractional
numbers, and real numbers.• Describe the binary number system.• Convert decimal numbers to binary and vice
versa.• Perform binary math operations such as
add, subtract, multiply, and divide.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Objectives
• Explain the hexadecimal number system.• Convert binary numbers to hexadecimal
numbers and vice versa.• Explain the octal number system.• Convert binary numbers to octal numbers
and vice versa.• Explain the binary coded decimal number
system and its use.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Objectives
• Convert decimal numbers to binary coded decimal.
• Explain the Gray code number system and its use.
• Explain ASCII and EBCDIC alphanumeric codes.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal Number System
• Decimal number system:– Has ten (10) digits running from zero (0)
through nine (9). – Decimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8,
and 9.– Each digit's value depends on the
position of the digit within the number.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal Number System (Cont.)
• Base, also called the radix:– Multipliers for the digits are numbers
constructed of the number system (10 in the decimal system) raised to the appropriate power.
– 10a
10 = Base or radixa = Power
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal Number System (Cont.)
• Values for the power of ten (10) numbers.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal Number System (Cont.)
Example:6310 = (6 × 103) + (3 × 102) + (1 × 101) + (0 × 100)= (6 × 1000) + (3 × 100) + (1 × 10) + (0 × 1)= 6000 + 300 + 10 + 0= 6310
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Fractional Numbers
• Fractional numbers:– Have weights that are negative powers of
ten (10).
Example: 0.812 = (8 × 10-1) + (1 × 10-2) + (2 × 10-3) = (8 × 0.1) + (1 × 0.01) + (2 × 0.001) = 0.8 + 0.01 + 0.002 = 0.812
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Real Numbers
• Real numbers:– Have weights that are both positive and
negative powers of ten (10).– Integer parts.– Fractional parts.
• Value of digits:– Digits.– Digits' positions.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Real Numbers (Cont.)
Example:547.165 = (5 × 102) + (4 × 101) + (7 × 100) + (1 ×
10–1) + (6 × 10–2) + (5 × 10–3)= (5 × 100) + (4 × 10) + (7 × 1) + (1 ×
0.1) + (6 × 0.01) + (5 × 0.001)= 500 + 40 + 7 + 0.1 + 0.06 + 0.005= 547.165
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Real Numbers (Cont.)
• Digits to the left of the decimal point represent the integer number.
• Digits to the right of the decimal point represent the fractional number.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Integer Numbers
• Integer numbers:– Have weights that are positive powers of
ten (10).– Can be positive or negative.– Zero is an integer number.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Number System
• Binary number system:– Has a base, also called a radix, of two (2).– Only the digits 1 and 0 are present.
• All binary numbers are created from combinations of these two digits.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Number System (Cont.)
• Least significant bit (LSB):– Binary digit to the far right-hand side of
the number.– Rightmost number has the smallest
value.• Most significant bit (MSB):
– Binary digit to the far left-hand side.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary-to-Decimal Conversion
• Converting binary-to-decimal:– Convert each bit to its equivalent decimal
value. – Add all of these decimal values.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal-to-Binary Conversion
• Convert integer part of a decimal number using:– Repeated division.– Successive division.
• Convert fractional part using:– Repeated multiplication.– Successive multiplication.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal-to-Binary Conversion (Cont.)
• Successive division method:– Integer decimal number is divided by two,
repeatedly.– Remainders make up the new binary
number.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Decimal-to-Binary Conversion (Cont.)
• Successive multiplication method:– Convert the fractional part of a decimal
number to binary.• MSB of the binary number:
– Decimal number is multiplied by two and the portion that is carried (if the product is greater than 0).
– Process is continued until the decimal part of the number becomes zero.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Addition
• Decimal number system:– Carry generated when the sum of two
digits is equal to 10.• Binary number system:
– Carry generated when the sum of two binary bits is equal to two.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Addition (Cont.)
• Ways that binary bits are added and how the carry bit is generated:0 + 0 = 00 + 1 = 11 + 1 = 0 with carry of 11 + 1 + 1 = 1 with carry of 1
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Subtraction
• In the decimal number system:– When the value of a digit is being
subtracted (the subtrahend) is greater than the value of the digit that it is being subtracted from (the minuend), a borrow from the next higher column (the column to the left) is required.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Subtraction (Cont.)
• Subtraction of binary numbers: – Ways binary bits are subtracted and
when a borrow bit is required:0 – 0 = 0 no borrow1 – 1 = 0 no borrow1 – 0 = 1 no borrow(1) 0 – 1 = 1 with a borrow of 1
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Multiplication
• In multiplication, the multiplicand is multiplied by each of the multiplier digits.– Results of each higher multiplier digit are
shifted one place to the left. – When each of the multiplicand’s digits
have been multiplied by the multiplier digits, all of the numbers are added.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Multiplication (Cont.)
• How binary bits are multiplied:0 × 0 = 00 × 1 = 01 × 0 = 01 × 1 = 1
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Division
• Division:– How many times a number called the
divisor can be subtracted from another number called the dividend.
– Similar to decimal division.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Division (Cont.)
• Subtraction routine:– Continues until the remainder is less than
the dividend.• Quotient:
– Number of times the divisor can be subtracted from the dividend.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Hexadecimal Number System
• Hexadecimal number system:– Used in medium to larger programmable
logic controllers (PLCs).– Often just called hex.– Used to display the PLC memory map
and to carry out the math instructions.– Created by grouping four binary bits.– Hexadecimal numbers use base of 16
and require fifteen digits.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Hexadecimal Number System (Cont.)
– Uses the numbers zero (0) through nine (9) for the first ten digits.
– Ten (10) through fifteen (15) are represented by letters A through F. • Digits representing 10, 11, 12, 13, 14, and 15
are displayed as A, B, C, D, E, and F respectively.
– Capital letter H or the small letter h is placed at the end of a hexadecimal number.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Hexadecimal Number System (Cont.)
Hexadecimal Binary Decimal0 0000 01 0001 12 0010 23 0011 34 0100 45 0101 56 0110 67 0111 78 1000 89 1001 9A 1010 10B 1011 11C 1100 12D 1101 13E 1110 14F 1111 15
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Hexadecimal Number System (Cont.)
• To form hex numbers from binary numbers, group binary number bits in groups of four.
• Swap out each group of four binary bits with its hex equivalent.
Example:111100010111 becomes 1111 0001 0111 which is
transformed to F 1 7 or F13h.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Hexadecimal Number System (Cont.)
• Reverse the process to convert to binary.
• Take each hex digit and swap it with the binary 4-bit equivalent.
Example:The number 37Ah becomes 0011 0111 1010 or
001101111010.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Octal Number System
• Octal number system:– Has a base of eight.– Therefore, only the digits zero (0) through
seven (7) are present.– Used to display the memory maps and
carry out the math instructions in some MicroLogix controllers.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Octal Number System (Cont.)
Octal Binary Decimal 0 000 0
1 001 1 2 010 2
3 011 3 4 100 4 5 101 5 6 110 6 7 111 7
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Octal Number System (Cont.)
• Form an octal number from a binary number by grouping binary number bits in groups of three.
• Swap out each group of three binary bits with its octal equivalent octal digit.
Example:• The number 11001111 becomes 011 001 111
which is transformed to 3 1 7 or 317O.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Octal Number System (Cont.)
• Reverse the process to convert to binary.– Take each octal digit and swap it with the
binary 3-bit equivalent.
Example:• The number 246 becomes 010 100 110 or
10100110.
• The capital letter O is placed at the end of an octal number.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Coded Decimal (BCD) System• Each 4 bits of binary numbers are
grouped to form a decimal number.• Four bit groups representing 10, 11,
12, 13, 14, and 15 are not valid numbers in the BCD number system.
• Only digits zero (0) through nine (9) are valid.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Coded Decimal (BCD) System (Cont.)
Binary Coded Decimal (BCD) Decimal 0000 0 0001 1
0010 2 0011 3 0100 4 0101 5 0110 6
0111 7 1000 8
1001 9
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Binary Coded Decimal (BCD) System (Cont.)
• To convert a number from any number system to BCD, first convert the number to decimal.
• Then, represent each decimal digit with a 4-bit binary number code.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Gray Code
• Servo control:– Closed-loop industrial control system that
is used to control the speed and position of an electric motor shaft.
• Optical encoders:– Generate codes that represent the
angular positions of the motor shafts.– Usually in a format called Gray code.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Gray Code (Cont.)
• Gray code system:– Similar to binary. – Converted to binary prior to arithmetic
operation. – Used for detecting the position of a motor
shaft. – Only one digit changes state (turns on or
off) as a number increments or decrements.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Gray Code (Cont.)
• Gray code system (continued):– Speed of the operation of a control
system increases.• Only one digit changes with every rotation of
the optical encoder disc attached to the motor shaft.
– Difficulty in doing arithmetic operations.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Gray Code (Cont.)Gray code Binary Decimal
0000 0000 0 0001 0001 1 0011 0010 2 0010 0011 30110 0100 40111 0101 50101 0110 60100 0111 71100 1000 81101 1001 9 1111 1010 10 1110 1011 11 1010 1100 12 1011 1101 13 1001 1110 141000 1111 15
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Alphanumeric Code
• Alphanumeric codes represent:– Letters– Numbers– Special symbols
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
American Standard Code for Information Interchange (ASCII)• 7-bit code• Used to represent alphabets, numbers,
characters, and control codes in computer systems.
• One hundred and twenty eight (27 = 128) different characters can be represented.
• Data is often sent in bytes (groups of eight bits).
• Eighth bit in one byte of transmitted data used for a parity bit.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Extended Binary Coded Decimal Interchange Code (EBCDIC)
• 8-bit code. • Alphanumeric code commonly encountered in
computer mainframe equipment.• Two hundred and fifty six (28 = 256) different
characters can be represented.– Uppercase and lowercase.– Numbers (1 thru 9).– Punctuation, control codes, and other characters.
• Commonly called Extended ASCII.
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Alphanumeric Codes
Permission granted to reproduce for educational use only.© Goodheart-Willcox Co., Inc.
Control Codes