670 likes | 1.08k Views
NUMBER SYSTEM. Compiled by : S. Agarwal, Lecturer & Systems Incharge St. Xavier’s Computer Centre, St. Xavier’s College Kolkata. March-2003. Introduction
E N D
NUMBER SYSTEM Compiled by : S. Agarwal, Lecturer & Systems Incharge St. Xavier’s Computer Centre, St. Xavier’s College Kolkata. March-2003
Introduction A number system defines a set of values used to represent quantity. We talk about the number of people attending class, the number of modules taken per student, and also use numbers to represent grades achieved by students in tests. Quantifying values and items in relation to each other is helpful for us to make sense of our environment. We do this at an early age; figuring out if we have more toys to play with, more presents, more lollies and so on. The study of number systems is not just limited to computers. We apply numbers every day, and knowing how numbers work will give us an insight into how a computer manipulates and stores numbers.
The Romans devised a number system which could represent all the numbers from 1 to 1,000,000 using only seven symbols • I = 1 • V = 5 • X = 10 • L = 50 • C = 100 • D = 500 • M = 1000 • A small bar placed above a symbol indicates the number is multiplied by 1000.
The Decimal Number System The primary number system used is a base ten number system. Base ten number systems are called decimal number systems. In decimal we have ten numerals, 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
Counting in decimal: When we count, we start at 1 and count up to 9. The next number is 10. That is, we create a place for the tens digit and put zero in the ones position. We continue to count by adding one to the ones place until we run out of digits again at 19. Then we reset the ones place to zero and increment the tens place to get 20. We continue in this way until we reach 99. At that point we create a third digit to hold hundreds and reset the tens and ones place to zero to get 100. And so on. Each time we change a digit, all the digits to its right are set to zero. So the number after 299 is 300, with zeros to the right of the 3.
9735 = 9000 is equivalent to 9 * 1000 is equivalent to 9 * 103 + 700 7 * 100 7 * 102 + 30 3 * 10 3 * 101 + 5 5 * 1 5 * 100 So 9735 = (9 * 103) + (7 * 102) + (3 * 101) + (5 * 100).
The Octal Number System We can use a number system with only eight numerals, 0 through 7. A system with only eight numerals is called octal.
Counting in Octal In octal, instead of ten digits, we only have eight. So we resort to changing the digits to the left more frequently. Counting in base 8, we get: 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27
octal-decimal octal-decimal octal-decimal octal-decimal octal-decimal octal-decimal octal-decimal Since the octal number 10 follows 7, 10 in octal is 8 in decimal. 11 in octal is 9 in decimal. And so on. 0 - 0 10 - 8 20 - 16 ... 70 - 56 100 - 64 ... 1 - 1 11 - 9 21 - 17 71 - 57 101 - 65 2 - 2 12 - 10 22 - 18 72 - 58 102 - 66 3 - 3 13 - 11 23 - 19 73 - 59 103 - 67 4 - 4 14 - 12 24 - 20 74 - 60 104 - 68 5 - 5 15 - 13 25 - 21 75 - 61 105 - 69 6 - 6 16 - 14 26 - 22 76 - 62 106 - 70 7 - 7 17 - 15 27 - 23 77 - 63 107 - 71
5732 = 5000 (octal) = 5 * 1000 (octal) = 5 * 83 = 5 * 512 (decimal) = 2560 (decimal) Octal Digit Positions and Values In base 8, each digit occupies a position worth eight times the position to its right, instead of ten times as in base 10. So if 5732 is an octal number, it can be read as: + 700 (octal) = 7 * 100 (octal) = 7 * 82 = 7 * 64 (decimal) = 448 (decimal) + 30 (octal) = 3 * 10 (octal) = 3 * 81 = 3 * 8 (decimal) = 24 (decimal) + 2 (octal) = 2 * 1 (octal) = 2 * 80 = 2 * 1 (decimal) = 2 (decimal) Total = 3034 (decimal) We total the decimal values of each octal digit to get the decimal equivalent. So 5732 (octal) is 3034 (decimal).
To convert a decimal number to octal, we simply repeat dividing by 8 and saving the remainder. To convert 3034 in decimal to octal, start by dividing 3034 by 8 to get 379 with a remainder of 2. The first remainder will be the last digit in the octal number; the second remainder will be the second digit from the right; and so on. That is, all we need to do is write the remainders right-to-left as we divide by 8: Step Divide Equals Remainder Digits (1) 3034 / 8 = 379 2 2 (3) 379 / 8 = 47 3 32 (5) 47 / 8 = 5 7 732 (6) 5 / 8 = 0 5 5732
The Hexadecimal Number System We can use a number system with sixteen numerals. A base 16 number system is call hexadecimal or just hex. We can use our usual 0 through 9 for the first ten digits, then use the letters A for 10, B for 11, C for 12, D for 13, E for 14 and F for 15.
Counting in Hexadecimal In hexadecimal, we count the same same way we did in decimal and octal. But instead of ten digits or eight digits, we have sixteen, 0-9, A-F. So we resort to changing the digits to the left less frequently than in decimal or octal. Counting in base 16, we get: 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
hex-dec hex-dec hex-dec hex-dec hex-dec hex-dec hex-dec 0 - 0 10 - 16 20 - 32 ... F0 - 240 100 - 256 ... 1 - 1 11 - 17 21 - 33 F1 - 241 101 - 257 2 - 2 12 - 18 22 - 34 F2 - 242 102 - 258 3 - 3 13 - 19 23 - 35 F3 - 243 103 - 259 4 - 4 14 - 20 24 - 36 F4 - 244 104 - 260 5 - 5 15 - 21 25 - 37 F5 - 245 105 - 261 6 - 6 16 - 22 26 - 38 F6 - 246 106 - 262 7 - 7 17 - 23 27 - 39 F7 - 247 107 - 263 8 - 8 18 - 24 28 - 40 F8 - 248 108 - 264 9 - 9 19 - 25 29 - 41 F9 - 249 109 - 265 A - 10 1A - 26 2A - 42 FA - 250 10A - 266 B - 11 1B - 27 2B - 43 FB - 251 10B - 267 C - 12 1C - 28 2C - 44 FC - 252 10C - 268 D - 13 1D - 29 2D - 45 FD - 253 10D - 269 E - 14 1E - 30 2E - 46 FD - 253 10D - 269 F - 15 1F - 31 2F - 48 FF - 255 10F - 271 Since the hex number A follows 9, A in hex is 10 in decimal. B in hex is 11 in decimal. After F in hex (15 in decimal) we have 10 (16 in decimal). And so on.
3F72 = 3000 (hex) = 3 * 1000 (hex) = 3 * 163 = 3 * 4096 (decimal) = 12288 (decimal) Hex Digit Positions and Values In base 16, each digit occupies a position worth sixteen times the position to its right, instead of ten times as in base 10 or eight times as in octal. So if 3F72 is an hex number, it can be read as: + F00 (hex) = F * 100 (hex) = 15 * 162 = 15 * 256 (decimal) = 3840 (decimal) + 70 (hex) = 7 * 10 (hex) = 7 * 161 = 7 * 16 (decimal) = 112 (decimal) + 2 (hex) = 2 * 1 (hex) = 2 * 160 = 2 * 1 (decimal) = 2 (decimal) Total = 16242 (decimal) We total the decimal values of each hex digit to get the decimal equivalent. So 3F72 (hex) is 16242 (decimal).
Step Divide Equals Remainder Digits Converting Decimal to Hex We can convert a decimal to hex using the same procedure we used to convert decimal to octal. The only difference is that we divide by 16 each time since we are working in base 16. In the following steps we convert 16242 from decimal to hex: (1) 16242 / 16 = 1015 2 = 2 (hex) 2 (2) 1015 / 16 = 63 7 = 7 (hex) 72 (3) 63 / 16 = 3 15 = F (hex) F72 (4) 3 / 16 = 0 3 = 3 (hex) 3F72 So 16242 in decimal is written as 3F72 in hex.
The Binary Number System The base 2 number system, called binary is based on powers of 2 and contains only two digits, 0 and 1. 01001001010101110101010001010101101 10101010000000111101010101011111010
Counting in Binary • With only two numerals, 1 (one) and 0 (zero), counting in binary is pretty simple. Just keep in mind the following: • 0 + 0 = 0 • 0 + 1 = 1 • 1 + 0 = 1 • 1 + 1 = 10 • 1 + 1 + 1 = 11
We we would count in binary as follows: bin-dec bin-dec bin-dec bin-dec 0 - 0 1000 - 8 10000 - 16 11000 - 24 1 - 1 1001 - 9 10001 - 17 11001 - 25 10 - 2 1010 - 10 10010 - 18 11010 - 26 11 - 3 1011 - 11 10011 - 19 11011 - 27 100 - 4 1100 - 12 10100 - 20 11100 - 28 101 - 5 1101 - 13 10101 - 21 11101 - 29 110 - 6 1110 - 14 10110 - 22 11110 - 30 111 - 7 1111 - 15 10111 - 23 11111 - 31
Binary Digit Positions and Values In base 2, each digit occupies a position worth two times the position to its right, instead of ten times as in base 10, eight times as in octal, or 16 as in hex. So if 1101001 is a binary number, it can be read as:
1101001 = 1000000 (bin) = 1 * 26 = 1 * 64 (decimal) = 64 (decimal) + 100000 (bin) = 1 * 25 = 1 * 32 (decimal) = 32 (decimal) + 00000 (bin) = 0 * 24 = 0 * 16 (decimal) = 0 (decimal) + 1000 (bin) = 1 * 23 = 1 * 8 (decimal) = 8 (decimal) + 000 (bin) = 0 * 22 = 0 * 4 (decimal) = 0 (decimal) + 00 (bin) = 0 * 21 = 0 * 2 (decimal) = 0 (decimal) + 1 (bin) = 1 * 20 = 1 * 1 (decimal) = 1 (decimal) TOTAL = 105 (decimal) We total the decimal values of each binary digit to get the decimal equivalent. So 1101001 (binary) is 105 (decimal).
Converting Decimal to Binary We can convert a decimal to binary by dividing by 2 each time since we are working in base 2. In the following steps we convert 105 from decimal to binary: Step Divide Equals Remainder Digits (1) 105 / 2 = 52 1 1 (2) 52 / 2 = 26 0 01 (3) 26 / 2 = 13 0 001 (4) 13 / 2 = 6 1 1001 (5) 6 / 2 = 3 0 01001 (6) 3 / 2 = 1 1 101001 (7) 1 / 2 = 0 1 1101001 So 105 in decimal is written as 1101001 in binary.
Converting Between Hex, Octal and Binary bin-octal-dec bin-octal-dec bin-octal-dec bin-octal-dec 0 - 0 - 0 1000 - 10 - 8 10000 - 20 - 16 11000 - 30 - 24 1 - 1 - 1 1001 - 11 - 9 10001 - 21 - 17 11001 - 31 - 25 10 - 2 - 2 1010 - 12 - 10 10010 - 22 - 18 11010 - 32 - 26 11 - 3 - 3 1011 - 13 - 11 10011 - 23 - 19 11011 - 33 - 27 100 - 4 - 4 1100 - 14 - 12 10100 - 24 - 20 11100 - 34 - 28 101 - 5 - 5 1101 - 15 - 13 10101 - 25 - 21 11101 - 35 - 29 110 - 6 - 6 1110 - 16 - 14 10110 - 26 - 22 11110 - 36 - 30 111 - 7 - 7 1111 - 17 - 15 10111 - 27 - 23 11111 - 37 - 31 Converting between binary, octal and hex is simple. Binary is base 2. Octal is base 8, and 8 is 23. That is, it takes exactly three binary digits to make one octal digit. If we line up the binary numbers and octal numbers, the connection is even more obvious:
What this means is that we can convert from binary to octal simply by taking the binary digits in groups of three and converting. Consider the binary number 10110100111100101101001011. If we take the digits in groups of three from right to left and convert, we get: 10110100111100101101001011 2 64745513 That is, 10110100111100101101001011 (binary) is 264745513 (octal).
Converting from octal to binary is just as easy. Since each octal digit can be expressed in exactly three binary digits, all we have to do is convert each octal digit to three binary digits. Converting 7563021 in octal to binary goes as follows: 7 5 6 3 0 2 1 111 101 110 011 000 010 001 So 7563021 (octal) is 111101110011000010001 (binary.)
Since (almost!) all computers have a binary architecture, octal is very useful to programmers. For humans, octal is more concise, smaller, easier to work with, and less prone to errors than binary. And since it is so easy to convert between binary and octal, octal is a favored number system for programmers.
In the same way, hex is base 16 and 16 is 24. That is, it takes exactly four binary digits to make a hex digit. By taking binary digits in groups of four (right to left) we can convert binary to hex. Consider once more the binary number 10110100111100101101001011. By grouping in fours and converting, we get: 10 1101 0011 1100 1011 0100 1011 2 D 3 C B 8 B So 10110100111100101101001011 (binary) is the same number as 2D3CB8B (hex), and the same number as 264745513 (octal).
Converting from hex to binary, simply write each hex digit as four binary digits. In this way we can convert 6F037C2: 6 F 0 3 7 C 2 0110 1111 0000 0011 0111 1100 0010 Since we can drop the leading zero, 6F037C2 (hex) is 110111100000011011111000010 (binary).
These days, octal tends to be used by programmers who come from a mini-computer background or who work with unicode. Hex tends to be preferred by programmers with a mainframe background or who work with colors. Many programmers are at home with either.
nibbleIn computers and digital technology, a nibble is four binary digits or half of an eight-bit byte. Maximum number in a nibble : 1111 = 15 A nibble can be conveniently represented by one hexadecimal digit.
BCD Binary-coded decimal, or BCD, is a method of using binary digits to represent the decimal digits 0 through 9. A decimal digit is represented by four binary digits, as shown below: The binary combinations 1010 to 1111 are invalid and are not used.
UNPACKED & PACKED BCD In unpacked BCD, a decimal digit is stored in one byte and in packed BCD, four bits are used to keep one digit, so two digits are stored in one byte, one in the lower half and one in the upper half of the byte. BCD and binary are not the same. For example, 4910 in binary is 1100012, but 4910 in BCD is 01001001BCD. 4 9 01001001 = 01001001BCD (PACKED BCD) Each decimal digit is converted to its binary equivalent.
BCD Conversion Conversion of decimal to BCD or BCD to decimal is similar to the conversion of hexadecimal to binary and vice versa. For example, let's go through the conversion of 26410to BCD. We'll use the block format that you used in earlier conversions. First, write out the decimal number to be converted; then, below each digit write the BCD equivalent of that digit: The BCD equivalent of 26410 is 001001100100BCD
To convert from BCD to decimal, simply reverse the process as shown: The DECIMAL equivalent of 100110000011BCD is 98310
ASCII Code ASCII, pronounced "ask-key", is the common code for microcomputer equipment. The standard ASCII character set consists of 128 decimal numbers ranging from zero through 127 assigned to letters, numbers, punctuation marks, and the most common special characters. The Extended ASCII Character Set also consists of 128 decimal numbers and ranges from 128 through 255 representing additional special, mathematical, graphic, and foreign characters.
The Standard ASCII character set is divided into four groups of 32 characters. The first 32 characters, form a special set of non-printing characters called the control characters. We call them control characters because they perform various printer/display control operations rather than displaying symbols.
Examples of common control characters include: • carriage return which positions the cursor to the left side of the current line of characters, • line feed which moves the cursor down one line on the output device • back space which moves the cursor back one position to the left • Unfortunately, different control characters perform different operations on different output devices. There is very little standardization among output devices. To find out exactly how a control character affects a particular device, you will need to consult its manual.
The second group of 32 ASCII character codes comprise various punctuation symbols, special characters, and the numeric digits. The most notable characters in this group include the: • space character • numeric digits 0 through 9 • Note that the numeric digits differ from their numeric values only in the high order nibble. By subtracting 30h from the ASCII code for any particular digit you can obtain the numeric equivalent of that digit.
The third group of 32 ASCII characters is reserved for the upper case alphabetic characters. The ASCII codes for the characters "A" through "Z" lie in the range 41h through 5Ah. Since there are only 26 different alphabetic characters, the remaining six codes hold various special symbols. The fourth, and final, group of 32 ASCII character codes are reserved for the lower case alphabetic symbols, five additional special symbols, and another control character (delete).
ISCII Indian Script Code for Information Interchange The ISCII code table is a super-set of all the characters required in the ten Brahmi-based Indian scripts. An optimal keyboard overlay for these scripts is made possible by the phonetic nature of the alphabet. The differences between scripts primarily are in their written forms, where different combination rules get used.
The 8-bit ISCII code retains the standard ASCII code, while the Indian script keyboard overlay is designed for the standard English can co-exist with Indian scripts. This approach also makes it feasible to use Indian scripts along with existing English computers and software, so long as 8-bit character codes are allowed.
The common INSCRIPT keyboard overlay allows typing of all the ten Indian scripts. This overlays fits on any existing English keyboard. Alternating between the English and Inscript overlay is achieved through the CAPSLOCK key. The INSCRIPT keyboard, provides a logical and intuitive arrangement of vowels and consonants. It is based both on the phonetic properties and the relative usage frequencies of the letters. Not only does this made the keyboard much easier to learn, but also enables a person to type subsequently in all the Indian scripts.
EBCDIC Extended Binary Coded Decimal Interchange Code It is an 8 bit character encoding used on IBM mainframes and AS/400s. It is descended from punched cards and the corresponding six bit Binary Coded Decimal Code that most of IBM's computer peripherals of the late 1950s and early 1960s used. Outside of such IBM systems, ASCII are normally used instead; EBCDIC is generally considered an anachronism. EBCDIC takes up eight bits, which are divided in two pieces. The first four bits are called the zone and represent the category of the character, whereas the last four bits are the called the digit and identify the specific character. There are a number of different versions of EBCDIC, customised for different countries.
1 1 1 1 0 0 0 0 0 0 1 1 1 0 1 0 1 0 1 0 0 1 0 1 1 1 0 0 1 1 0 0 --- --- --- --- --- --- --- --- --- --- --- --- 0 01 01 10 11 10 10 01 10 01 01 00 The Binary Addition Algorithm To add two 1-bit (representations of) integers: Count the number of ones in a column and write the result in binary. The right bit of the result is placed under the column of bits. The left bit is called the "carry out of the column".
A A B B CarryDigit C CARRY UnitDigit UNIT 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1
Signed Binary Integers We will not be using a minus sign (-) to represent negative numbers. We would like to represent our binary numbers with only two symbols, 0 and 1. There are a few ways to represent negative binary numbers. The simplest of these methods is called ones complement, where the sign of a binary number is changed by simply toggling each bit (0's become 1's and vice-versa). This has some difficulties, among them the fact that zero can be represented in two different ways (for an eight bit number these would be 0000 0000 and 1111 1111)., we will use a method called two's complement notation which avoids the pitfalls of one's complement.