640 likes | 1.23k Views
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.
E N D
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. • Perform binary math operations such as add, subtract, multiply, and divide.
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.
Objectives • Convert decimal numbers to binary coded decimal. • Explain the Gray code number system and its use. • Explain ASCII and EBCDIC alphanumeric codes.
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.
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 radix a = Power
Decimal Number System (Cont.) • Values for the power of ten (10) numbers.
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
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
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.
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
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.
Integer Numbers • Integer numbers: • Have weights that are positive powers of ten (10). • Can be positive or negative. • Zero is an integer number.
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.
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.
Binary-to-Decimal Conversion • Converting binary-to-decimal: • Convert each bit to its equivalent decimal value. • Add all of these decimal values.
Decimal-to-Binary Conversion • Convert integer part of a decimal number using: • Repeated division. • Successive division. • Convert fractional part using: • Repeated multiplication. • Successive multiplication.
Decimal-to-Binary Conversion (Cont.) • Successive division method: • Integer decimal number is divided by two, repeatedly. • Remainders make up the new binary number.
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.
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.
Binary Addition (Cont.) • Ways that binary bits are added and how the carry bitis generated: 0 + 0 = 0 0 + 1 = 1 1 + 1 = 0 with carry of 1 1 + 1 + 1 = 1 with carry of 1
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.
Binary Subtraction (Cont.) • Subtraction of binary numbers: • Ways binary bits are subtracted and when a borrow bitis required: 0 – 0 = 0 no borrow 1 – 1 = 0 no borrow 1 – 0 = 1 no borrow (1) 0 – 1 = 1 with a borrow of 1
Binary Multiplication • In multiplication, the multiplicandis multiplied by each of the multiplierdigits. • 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.
Binary Multiplication (Cont.) • How binary bits are multiplied: 0 × 0 = 0 0 × 1 = 0 1 × 0 = 0 1 × 1 = 1
Binary Division • Division: • How many times a number called the divisorcan be subtracted from another number called the dividend. • Similar to decimal division.
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.
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.
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.
Hexadecimal Number System (Cont.) Hexadecimal Binary Decimal 0 0000 0 1 0001 1 2 0010 2 3 0011 3 4 0100 4 5 0101 5 6 0110 6 7 0111 7 8 1000 8 9 1001 9 A 1010 10 B 1011 11 C 1100 12 D 1101 13 E 1110 14 F 1111 15
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.
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.
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.
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
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.
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.
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.
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
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.
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.
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.
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.
Gray Code (Cont.) Gray code Binary Decimal 0000 0000 0 0001 0001 1 0011 0010 2 0010 0011 3 0110 0100 4 0111 0101 5 0101 0110 6 0100 0111 7 1100 1000 8 1101 1001 9 1111 1010 10 1110 1011 11 1010 1100 12 1011 1101 13 1001 1110 14 1000 1111 15
Alphanumeric Code • Alphanumeric codes represent: • Letters • Numbers • Special symbols
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.
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.