Binary Numbers PDF
Document Details
Uploaded by GloriousSakura8157
Tags
Summary
This document provides a basic introduction to binary numbers, including their representation, weights, and conversions to decimal. The content covers the fundamental concepts of binary numbers and demonstrates conversion examples. Some exercises are also included, focused mainly on converting between decimal and binary systems.
Full Transcript
Binary Numbers Digital Systems can process, store and transmit data more efficiently as they assign discrete values to each point. They usually use the binary (base-2) number system. Binary numbers are written in base 2 and need only the digits 0,1. This makes it easier to assign numerical values...
Binary Numbers Digital Systems can process, store and transmit data more efficiently as they assign discrete values to each point. They usually use the binary (base-2) number system. Binary numbers are written in base 2 and need only the digits 0,1. This makes it easier to assign numerical values to physical parameters. A binary digit ( 0 or 1) is called a ' bit' A group of eight bits is called a ' byte'1 A group of bits processed in a CPU as a single unit, most commonly 8, 16, 32, or 64 bits A binary number consists of bits. The bits are summed with the weights which are powers of 2 and increase from right to left (in the same way as a decimal number is a sum digits weighed by powers of 10). So the weights allocated to bits are as shown below MSB(Most Significant2 Bit) LSB(Least Significant Bit) Digit Position 7 6 5 4 3 2 1 0 Weight 27 26 25 24 23 22 21 20 Value 128 64 32 16 8 4 2 1 Binary Number 1 0 1 1 0 0 1 0 This binary number 101100102 is hence equal to = 1×128 + 0×64 + 1×32 + 1×16 + 0×8 + 0×4 + 1×2 + 0×1 = 128 + 32 + 16 + 2 = 17810 1 A group of 4 bits is known as a Nibble 2 Significance e.g £7,654.32 The table below shows the binary representation of the first ten decimal numbers Decimal Binary Number Number (Values) 8421 0 0 0 1 1 1 2 10 2+0 3 11 2+1 4 100 4+0+0 5 101 4+0+1 6 110 4+2+0 7 111 4+2+1 8 1000 8+0+0+0 9 1001 8+0+0+1 Questions 1. Convert the following binary numbers into decimal. a) 101 b) 110 c) 10000 d) 10101 e) 10110 Binary to Decimal Conversion Converting binary numbers to decimal is straightforward, you need to multiply the bits by the corresponding weight (power of two) and add them. For an n-bit number B = bn−1.....b1b0 For example, (101101)2 = 25×1 + 24×0 + 23×1 + 22×1 + 21×0 + 20×1 = 32 + 8 + 4 + 1 = (45)10 Decimal to Binary Conversion For converting from decimal number to its binary equivalent, one commonly used method is to divide the decimal number by 2 and record the remainder. The process continues till the answer is zero. The remainders then form the equivalent binary number, starting from the last remainder as the most significant bit (MSB). For example, 157 ÷ 2 = 78 with a remainder of 1 Least significant bit (LSB) 78 ÷ 2 = 39 with a remainder of 0 39 ÷ 2 = 19 with a remainder of 1 19 ÷ 2 = 9 with a remainder of 1 9 ÷ 2 = 4 with a remainder of 1 4 ÷ 2 = 2 with a remainder of 0 2 ÷ 2 = 1 with a remainder of 0 1 ÷ 2 = 0 with a remainder of 1 Most significant bit (MSB) Hence we get (157)10 = (10011101)2 Problems 1. Convert the following decimal numbers into binary. a) 50 b) 75 c) 99 d) 1024 2. Convert the following binary numbers into decimal. a) 1110 b) 11010 c) 1000000 d) 11111111 Number Bases Commonly used Number bases are 1. Decimal (base-10): We use decimal system base 10, makes it easier to add/subtract/multiply numbers 2. Binary (base-2): Digital Computer uses binary number system because it is easier to assign two values to any physical parameter 3. Hexadecimal (base-16): Handling long binary numbers becomes cumbersome, it is convenient to combine the binary digits in groups of four and obtain a hexadecimal equivalent number. More commonly used to represent memory address and to represent OP-Codes (Operation codes) 4. Octal (base-8): This combines three binary digits to form an equivalent octal number. The one main disadvantage of Binary Numbers is that the binary equivalent of a large decimal number can be quite long, which makes it difficult to both read or write without producing errors especially when working with 16 or 32-bit numbers. One common way of overcoming this problem is to arrange the binary numbers into groups of four in Hexadecimal, starting with the least significant digit at the right hand side. This Hexadecimal or simply "Hex" numbering system uses the Base of 16 system. Hence, it uses 16 (sixteen) different digits with a combination of numbers from 0 to 9 and the capital letters A to F to represent its Binary or Decimal equivalent. We can make life easier by splitting these large binary numbers up into even groups to make them easier to write down and more understandable. For example, the following groups of binary digits 1101 1100 11112 are much easier to read and understand than 1101110011112 when they are all bunched up together. By dividing a binary number up into groups of 4 bits, each group or set of 4 digits (hex numbers) can now have a possible value of between "0000" (0) and "1111" (8+4+2+1 = 15) giving a total of 16 different number combinations from 0 to 15. Two hexadecimal numbers are required for each byte. Also, since 16 in the decimal system is the fourth power of 2 (or 2 4), one hex digit has a value equal to four binary digits. The Hex number system has the numbers 0 to 9 same as in the original decimal system, but the numbers from 10 to 15 are represented by capital letters of the alphabet from A to F inclusive and the relationship between decimal, binary and hexadecimal number system is shown. Hexadecimal Decimal Binary Octal 10 1 8421 16 1 81 0 0 0 0 1 1 1 1 2 10 2 2 3 11 3 3 4 100 4 4 5 101 5 5 6 110 6 6 7 111 7 7 8 1000 8 10 9 1001 9 11 10 1010 A 12 11 1011 B 13 12 1100 C 14 13 1101 D 15 14 1110 E 16 15 1111 F 17 So, now we can write the binary number, 1101110011112 = (211 + 210 + 28 + 27 + 26+ 23+ 22+ 21+ 20)10 = (2048 + 1024 + 256 + 128 + 64 + 8 + 4 + 2 + 1) 10 = 353510 Conversion to hexadecimal number system is simpler, it requires dividing the binary into four bit 'nibbles' 1101110011112 = 1101 1100 11112 = DCF16 Hexadecimal Numbers So we now know how to convert 4 binary digits into a hexadecimal number. But what if we had more than 4 binary digits how would we count in hexadecimal beyond the final letter F. The simple answer is to start over again with another set of 4 bits as follows. 0...to...9, A,B,C,D,E,F, 10...to...19, 1A, 1B, 1C, 1D, 1E, 1F, 20, 21....etc Do not get confused, 10 and 20 are NOT ten and twenty, they are one-zero and two-zero in hexadecimal. In fact twenty does not exist as a hexadecimal digit. With two hexadecimal digits we can count up to FF which is equal to decimal 255. Likewise, to count higher than FF we would add a third hexadecimal digit to the left so the first 3-digit hexadecimal number would be 100 16 (25610), and the last would be FFF16 (409510). The maximum decimal number that can be counted by an N-digit hexadecimal number is 16N−1. The maximum 4-digit hexadecimal number is FFFF 16 which is equal to 65,535 in decimal and so on. Q How to convert a binary number to hexadecimal if the number of bits are not a multiple of four? We can add zero's to the left of the most significant bit, the MSB, if the number of binary bits is not a multiple of four. For example, 11001011011001 2 is a fourteen-bit binary number that is too large for just three hexadecimal digits, yet too small for a four-digit hexadecimal number. The answer is to ADD additional zero's to the leftmost bit until we have a complete four-bit binary number or multiples thereof. Adding Additional 0's to a Binary Number Binary Number 0011 0010 1101 1001 Hexadecimal Number 3 2 D 9 The main advantage of a Hexadecimal Number is that it usually needs less (or otherwise an equal number of) digits than in binary or decimal to represent a number. Secondly, conversion from/to binary is very simple and straightforward. Example No1 Convert the following Binary number 1110 1010 2 into its Hexadecimal number equivalent. 111010102 Group the bits into four's starting from the right hand side = 1110 1010 = E A Then, the hexadecimal equivalent of the binary number 1110 10102 is EA16 Example No2 Convert the following Hexadecimal number 3FA716 into its Binary equivalent, and also into its Decimal or Denary equivalent using subscripts to identify each numbering system. 3FA716 = 0011 1111 1010 01112 = 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 32 + 4 + 2 + 1 = 16,29510 Then, the Decimal number of 16,295 can be represented as:- 3FA716 in Hexadecimal or 0011 1111 1010 01112 in Binary Problems 1. Convert the following hex numbers into binary directly. a) F8 b) 144 c) E75 d) EFC 2. Convert the following binary numbers into hexadecimal. a) 101101 b) 101110111 c) 101 d) 100000 Decimal to Hexadecimal Hexadecimal to Decimal Conversion Hexadecimal to decimal conversion is based on the same principle as for binary to decimal conversion except that base is 16. For an n-digit hexadecimal number, H = hn−1.....h1h0 Equivalent decimal number can then be calculated as D = 16n−1×hn-1 +..... + 161×h1 + 160×h0 For example, (37F)16 = 162×3 + 161×7 +160×15 = 256×3 + 16×7 + 1×15 = 768 + 112 + 15 = (895)10 Decimal to Hexadecimal Conversion This conversion is not much needed as usually hex numbers are obtained from binary numbers. Decimal numbers can be converted to hex equivalent by dividing the number by 16 and recording the remainders. For example, with a remainder of 8 Least Significant Digit 1128 ÷ 16 = 70 with a remainder of 6 70 ÷ 16 = 4 with a remainder of 4 Most Significant Digit 4 ÷ 16 = 0 Hence we get (1128)10= (468)16 Problems 1. Convert the following decimal numbers into hexadecimal. a) 64 b) 98 c) 32 d) 109 2. Convert the following hex numbers into decimal. a) F8 b) 144 c) 930 d) 57A Octal Numbers Octal Numbers are very similar to hexadecimal numbering system except that an Octal digit is equivalent to 3 bits. Then the main characteristic of an Octal Numbering System is that there are 8 distinct counting digits from 0 to 7 with each digit having a weight or value of just 8 starting from the least significant bit (LSB). As the base of an Octal Numbers system is 8, which also represents the number of individual numbers used in the system, the subscript 8 is used to identify a number expressed in octal. For example, 2378 Like hexadecimal, the octal number system provides a convenient way of converting large binary numbers into smaller groups. However, octal numbering is used less frequently than the more common hexadecimal numbering system and has almost disappeared. To count above 7 in octal we add another column and start over again in a similar way to hexadecimal. 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21....etc Again do not get confused, 10 and 20 are NOT ten and twenty, they are one-zero and two-zero in octal exactly the same as for hexadecimal. With two octal digits, we can count up to 778 (which is equal to 63 in decimal), with three octal digits up to 7778 (511 in decimal), with four octal digits up to 77778 (4095 in decimal) and so on. Maximum decimal number that can be represented by an N- digit octal number is 8N−1. Example No1. Using our previous binary number of 11010101110011112 converting it into the octal equivalent is shown as follows. Binary Digit Value 001101010111001111 Group the bits into three's starting from 001 101 010 111 001 111 the right hand side 1 5 2 7 1 7 Octal Number form Thus, 0011010101110011112 in Binary form is equivalent to 1527178 in Octal form or 54,73510 in Decimal. As the Octal Number system is very similar to hexadecimal, but each octal digit can be represented by three bits 1101110011112 = 110 111 001 1112 = 67178 = 353510