Numbering Systems Lecture PDF

Summary

This document provides an overview of numbering systems, including decimal, binary, octal, and hexadecimal systems. It details concepts like information representation and conversion between different number bases. The presentation also touches upon topics such as digital systems, adding binary numbers, shifts, and more.

Full Transcript

1 NUMBERING SYSTEM Dr. Samar A. Said First term 2024-2025 POINTS TO BE COVERED: Information representation Digital systems Radix number system Decimal number Binary number Octal number Hexadecimal num...

1 NUMBERING SYSTEM Dr. Samar A. Said First term 2024-2025 POINTS TO BE COVERED: Information representation Digital systems Radix number system Decimal number Binary number Octal number Hexadecimal number Number conversion From any base (radix) to decimal number From decimal to any base (radix) From base 2 to base 8 or 16 and vice verse Signed binary numbers Adding binary numbers 2 Shift Information Representation All information must be rendered into binary in order to be stored on a computer. Besides numbers, almost all applications must store characters and string information. Images are pervasive in today’s internet world and must be rendered in binary to be handled by internet browsers. Information representation ASCII ) American Standard Code for Information Interchange( – is used for the representation of text such as symbols, letters, digits, etc. Unicode –the universal character encoding used to process, store and facilitate the interchange of text data in any language ASCII American Standard Code for Information Interchange(ASCII) and was first launched in 1963. ASCII codes are used for the representation of text such as symbols, letters, digits, etc. ASCII is used for representing 128 English characters in the form of numbers, with each letter being assigned to a specific number in the range 0 to 127. For e.g., the ASCII code for uppercase A is 65, uppercase B is 66, and so on. Most computers are using ASCII encoding for text representation, which makes transferring data from one device to another a lot easier. ASCII UNICODE Unicode provides a unique way to define every character in every spoken language of the world by assigning it a unique number. The Unicode standard is maintained by the Unicode Consortium and defines more than 1,40,000 characters from more than 150 modern and historic scripts along with emoji. Unicode can be defined with different character encoding like UTF-8, UTF-16, UTF-32, etc. UTF-8 requires 8, 16, 24 or 32 bits (one to four bytes) to encode a Unicode character, UTF-16 requires either 16 or 32 bits to encode a character, and UTF-32 always requires 32 bits to encode a character. Among these UTF-8 is the most popular as it used in over 90% of websites on the World Wide Web as well as on most modern Operating systems like Windows. DIGITAL SYSTEMS Digital systems are designed to store, process, and communicate information in digital form. They manipulate discrete information (A finite number of elements) Example discrete sets 10 decimal digits, the 26 letters of alphabet Information is represented in (digital)binary form They are found in a wide range of applications, including process control, communication systems, digital instruments, and consumer products. 7 BINARY SIGNALS It means two-states 1 and 0 True and false On and off A single “on/off”, “true/false”, “1/0” is called a bit Example: toggle switch 8 BYTE Computer memory is organized into groups of eight bits Each eight bit group is called a byte 9 Radix Number System The radix or base is the number of unique digits, including the digit zero, used to represent numbers. For example, for the decimal system (the most common system in use today) the radix is ten, because it uses the ten digits from 0 through 9. Base – 10 (decimal numbers) 0123456789 Base – 2 (binary numbers) 01 Base – 8 (octal numbers) 01234567 Base – 16 (hexadecimal numbers) 10 0123456789abcdef DECIMAL NUMBER  Exactly ten distinct numerals in order to represent all possible values for each position in the number, and hence to enable us to represent all possible integer numbers in decimal notation.  0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 values  For example, a number like "0123456789" has ten positions and each position can contain the digits 0-9.  Each digit position has a weight associated with it.  Each digit corresponds to a power of 10 based on its position in the number  Number’s value = a weighted sum of the digits  Number’ value = digit * 10^x + digit * 10^x where x = (position number). 123410 = 1x 103 + 2x 102 + 3x101 +4x100 = 1000 + 200 + 30 +4 = 123410 DECIMAL NUMBER Example 9876 = 9x 10^3 + 8x 10^2 + 7x10^1 +6x10^0 = 9000 + 800 + 70 +6 = 9876 In the decimal system, there are 10 digits (0 through 9) which combine to form numbers as follows:  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22... BINARY NUMBER  Base (radix) is 2  Two symbols: 0 and 1  Each place is weighted by the power of 2 All the information in the digital computer is represented as bit patterns  What is a bit pattern? This is one bit  01010101  This is called as the bit pattern and has 8 bits BINARY NUMBER  0101 0101  This pattern is represented as follows in the digital computer Bit7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 0 1 0 1 0 1 0 1  A single bit can represent two states: 0 1  Therefore, if you take two bits, you can use them to represent four unique states: 00, 01, 10, & 11  And, if you have three bits, then you can use them to represent eight unique states: 000, 001, 010, 011, 100, 101, 110, & 111 With every bit you add, you double the number of states you can represent. Therefore, the expression for the number of states with n bits is 2^n. Most computers operate on information in groups of 8 bits BINARY NUMBER Bit7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 0 1 0 1 0 1 0 1 There are 8 bits in the above table Group of 4 bits = 1 Nibble Group of 8 bits = 1 Byte Group of 16 bits = 1 Word 2 Bytes = 1 Word Bit 0 is called the Least Significant Bit LSB Bit 7 is called the Most Significant Bit MSB BINARY NUMBER Bit positions and their values Bit7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 OTHER NUMBER SYSTEMS Therefore, binary quantities are written in a base-8 ("octal") or, much more commonly, a base-16 ("hexadecimal" or "hex") number format. Octal and hex are a convenient way to represent binary numbers, as used by computers. OCTAL NUMBER Base = 8 or ‘o’ or ‘Oct’ 8 symbols: { 0, 1, 2, 3, 4, 5, 6, 7} Example 123, 567, 7654 etc Hexadecimal Number Base = 16 or ‘H’ or ‘Hex’ 16 symbols: { 0, 1, 2, 3, 4, 5, 6, 7,8,9 } { 10=A, 11=B, 12=C, 13=D, 14=E, 15= F} {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} It uses 6 Letters ! Example AB12, 876F, FFFF etc Conversion From One Radix To Another From any base (radix) to decimal number From decimal to any base (radix) From base 2 to base 8 or 16 and vice verse. F. Alakeel 20 Conversion From One Radix To Another Conversion from any base (radix) to decimal number 21 Conversion from any base (radix) to decimal number A number in a base-r system X = xn-1xn-2... x1x0. x-1 x-2... x-(m-1) x-m Value( x) = xn−1  r n−1 + xn−2  r n−2 +... + x0  r 0 + x−1  r −1 + x−2  r −2 +... + x−m  r − m (234.26)6 = 2  62 + 3  61 + 4  60 + 2  6−1 + 6  6−2 = (94.5)10 (45.4)8 = 4  81 + 5  80 + 4  8−1 = (39.5)10 Example: Conversion From binary to decimal Example: Convert 11012 Multiply each 1 bit by the appropriate power of 2 and add them together. 1 0 1 1 Bit 1 Bit 0 Bit 3 Bit 2 Conversion From binary to decimal Example: Convert 11012 Bit7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 1 1 0 1 Multiply with 8 x 1 + 4 x 1 + 2 x 0 + 1x 1 = 8 + 4 + 0 + 1 these values = 13 Conversion From binary to decimal Example: 10112 or 1011 B = 1 x 23 + 0 x 22 + 1 x 21 + 1 x 20 = 8 + 0 + 2 +1 = 1110 Example: 101102 or 10110 B 1 x 24+0 x 23 + 1 x 22 + 1 x 21 + 0 x 20 = 16 + 0 + 4 +2+0 = 2210 From Octal to decimal Number How to convert 3258 back to Decimal ? Use this table and multiply the digits with the position values Digit Digit Digit Digit Digit Digit Digit Digit 8 7 6 5 4 3 2 1 87 86 85 84 83 82 81 80 …… …… 32768 4096 512 64 8 1 From Octal to decimal Number How to convert 3258 back to Decimal ? Consider the above number 3 2 5 (8) Digit 1 Digit 3 Digit 2 3 x 82 + 2 x 81 + 5 x 80 = 3 x 64 + 2 x 8 + 5 x 1 = 192 +16 + 5 = 213 From Octal to decimal Number Example Convert 6118 Consider the above number 6 1 1 (8) Digit 1 Digit 3 Digit 2 6 x 82 + 1 x 81 + 1 x 80 = 6 x 64 + 1 x 8 + 1 x 1 = 384 + 8 + 1 = 393 From Hexadecimal to decimal Number How to convert D516 back to Decimal ? Use this table and multiply the digits with the position values Digit Digit Digit Digit Digit Digit Digit Digit 8 7 6 5 4 3 2 1 167 166 165 164 163 162 161 160 …… …… ….. …… 4096 256 16 1 From Hexadecimal to decimal Number How to convert D516 back to Decimal ? Consider the above number D 5 (16) Digit 1 Digit 2 D x 161 + 5 x 160 = 13 x 16 + 5 x 1 = 208 + 5 = 213 Binary Systems 31 Binary Systems 32 Binary Systems 33 Binary Systems 34 Conversion From One Radix To Another Conversion from decimal to any base (radix) F. Alakeel 35 Conversion from decimal to any base (radix) For each digit position Divide decimal number by the base (e.G. 2) 2. The remainder is the lowest-order digit 3. Repeat first two steps until no divisor remains. Example: Convert Decimal 13 (13 10) to Binary : Repeated division by 2 (till quotient is zero) Divide-by -2 Quotient Remainder Binary Bits 13/2 6 1 Bit 0 = 1 6/2 3 0 Bit 1 = 0 3/2 1 1 Bit 3 = 1 1/2 0 1 Bit 4 = 1 36 Answer = 11012 Conversion from decimal to any base (radix) From decimal to base-r Separate the number into an integer part and a fraction part For the integer part Divide the number and all successive quotients by r until reach 0 Accumulate the remainders For the fraction part Multiply the fraction part by r until reach 0 after point Accumulate the result 165 4 0.6875 x 2 = 1 + 0.3750 23 2 0.3750 x 2 = 0 + 0.7500 3 3 0.7500 x 2 = 1 + 0.5000 0 0.5000 x 2 = 1 + 0.0000 (165)10 = (324) 7 (0.6875)10 = (0.1011) 2 Binary Systems 37 Conversion from decimal to any base (radix) NONTERMINATING BASE 2 FRACTION Some terminating base 10 fractions cannot be converted into an equivalent terminating base 2 fraction From Decimal to octal Number Repeated Division by 8 Example 21310 = ( )8 ? Divide-by -8 Quotient Remainder Octal digit 213 / 8 26 5 Lower digit = 5 26 / 8 3 2 Second digit =2 3/8 0 3 Third digit =3 Answer = 3258 From Decimal to octal Number Convert 393 to octal Divide-by -8 Quotient Remainder Octal digit 393 / 8 49 1 Lower digit = 1 49 / 8 6 1 Second digit =1 6/8 0 6 Third digit =6 Answer = 6118 From Decimal to Hexadecimal Number Repeated Division by 16 Example 21310 = ( )16 ? Divide-by -16 Quotient Remainder Hex digit 213 / 16 13 5 Lower digit = 5 13 / 16 0 13 Second digit =D Answer = D516 Conversion From One Radix To Another From base 2 to base 8 or 16 and vice verse. F. Alakeel 43 From base 2 to base 8 or 16 and vice verse. From binary to octal Divide into groups of 3 bits Example 11001101001000.1011011 = 31510.554 From octal to binary Replace each octal digit with three bits Example 75643.5704 = 111101110100011.101111000100 44 From base 2 to base 8 or 16 and vice verse From binary to hexadecimal Divide into groups of 4 bits Example 11001101001000.1011011 = 3348.B6 From hexadecimal to binary Replace each digit with four bits Example 7ba3.Bc4 = 111101110100011.101111000100 45 SIGNED BINARY NUMBERS  Unsigned representation can be used for positive integers  How about negative integers?  Everything must be represented in binary numbers  Computers cannot use – or + signs  Three different systems have been used  Signed magnitude  One’s complement  Two’s complement  NOTE: For negative numbers the sign bit is always 1, and for positive numbers it is 0 in these three systems SIGNED MAGNITUDE The leftmost bit is the sign bit (0 is + and 1 is - ) and the remaining bits hold the absolute magnitude of the number Examples -47 = 1 0 1 0 1 1 1 1 47 = 0 0 1 0 1 1 1 1 For 8 bits, we can represent the signed integers –127 to +127 How about for N bits? ONE’S AND TWO’S COMPLEMENT One’s complement Replace each 1 by 0 and each 0 by 1 Example (-6) First represent 6 in binary format (00000110) Then replace (11111001) Simply replace 1’s and 0’s 1’s complement of 10100010 01011101 ONE’S AND TWO’S COMPLEMENT Two’s complement Find one’s complement Add 1 Example (-6) First represent 6 in binary format (00000110) One’s complement (11111001) Two’s complement (11111010) Example 2’s complement of 10111001 01000110 + 1 = 01000111 Add 1 to 1’s complement 2’s complement of 10100010 01011101 + 1 = 01011110 OPERATIONS ON UNSIGNED NUMBERS Addition of unsigned numbers 1. Add bits from right to left on a column by column basis 2. Compute a sum bit and a carry out bit (carry in to next stage) 50 OPERATIONS ON UNSIGNED NUMBERS EXAMPLE +5 00000101 +11 00001011 +16 00010000 51 OPERATIONS ON UNSIGNED NUMBERS Subtraction of unsigned numbers 1. Subtract bits from right to left on a column by column basis. 2. Compute a difference bit and a borrow bit (used in next stage). 52 OPERATIONS ON UNSIGNED NUMBERS EXAMPLE 53 OPERATIONS ON TWO’S COMPLEMENT NUMBERS Addition of two’s complement numbers Given x and y in two’s complement on n bits 1-add arithmetically bit by bit from right to left 2-discard the carry out of the most significant bit Overflow : Adding two positive numbers produces a negative result Adding two negative numbers produces a positive result Note: Adding operands of unlike signs never produces an overflow 54 OPERATIONS ON TWO’S COMPLEMENT NUMBERS 55 OVERFLOW DETECTION to detect the overflow: If the operands have the same sign The result must have the same sign Otherwise overflow 56 ARITHMETIC ADDITION Usually represented by 2’s complement Discard -5 11111011 -5 11111011 +11 00001011 -11 11110101 +6 100000110 -16 111110000 Discard SHIFT Shift left Quick multiplication of unsigned numbers by powers of 2: Shift left n times to multiply by 2^n Fill in with 0’s from the right Overflow if the last 1 is discarded from the left SHIFT Shift right Quick division of unsigned numbers by powers of 2: Shift right n times to divide by 2^n Fill in with 0’s from the 𝑙𝑒𝑓𝑡 Underflow if the last 1 is discarded from the right quick multiplication OUTLINE OF COURSE CONTENTS GOING TO BE COVERED DURING COURSE: INTRODUCTION NUMBERING SYSTEMS NEGATIVE NUMBERS AND ADDING IN BINARY BOOLEAN ALGEBRA FLOW CHART, PSEUDO CODE, AND ALGORITHM HOW TO WRITE A C++ PROGRAM. INPUT AND OUTPUT CONDITIONS LOOPS ARRAY

Use Quizgecko on...
Browser
Browser