← Back to Book Detail

Binary-Decimal Conversions (36/67) -- Contemporary Digital Humanities

Browse
53%

Binary-Decimal Conversions

Binary-Decimal Conversions Conversions from binary to decimal and vice-versa are based on the calculations shown above. For converting binary to decimal, powers of two are summed, where a “1” appears in the binary number, such as was shown above for the conversion 101112 = 2310. A simple approach to convert decimal to binary is illustrated with an example. Repeatedly divide by 2, and record the remainder until the remainder is zero. The remainders are recorded from right to left. For example, for converting 23 to binary (the converse of the example above) yields the following calculations: 23/2 = 11 with a remainder of 1. Since the remainder is 1, record binary number 1. 11/2 = 5 with a remainder of 1. Record the binary number = 11. 5/2 = 2 with a remainder of 1. Record the binary number = 111. 2/2 = 1 with a remainder of 0. Record the binary number = 0111. 1/2 = 0 with a remainder of 1. Record the binary number 10111. Therefore, 2310 = 101112, as expected. Computers use fixed-length binary numbers to represent integers. For example, 2 bits can represent 22 = 4 different values, 00, 01, 10, and 11, or (0, 1, 2, and 3 in decimal). With 4 bits, 24 = 16 values, from 0 to 15, can be represented: 00002 = 010 00012 = 110 00102 = 210 00112 = 310 01002 = 410 01012 = 510 01102 = 610 01112 = 710 10002 = 810 10012 = 910 10102 = 1010 10112 = 1110 11002 = 1210 11012 = 1310 11102 = 1410 11112 = 1510 Numbers represented by 8-bits are very common in digital computer systems. Characters, for example, are indicated by 8-bits. There are 28 = 256 different 8-bit numbers, ranging from 0 to 255. Binary arithmetic is arithmetic based on binary numbers and operating on bits. The basic binary addition operations are: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10. The “1”, or most significant digit in the sum 1 + 1 = 10, is known as the carry bit. When adding larger binary numbers, binary arithmetic is performed from right to left, as in decimal addition, and the carry bits are taken into account. The concept will be illustrated with examples of adding 4-bit binary numbers. Example 1: 1010 + 0100 1110 In decimal arithmetic, 10102 = 1010, 01002 = 410, and 10102 + 01002 = 11102 = 1410. Example 2: 1010 + 1100 10110 The underlined “1” is the carry bit. In decimal arithmetic, 10102 = 1010, 11002 = 1210, and 10102 + 11002 = 101102 = 2210. Example 3: 11 1010 + 0110 10000 The underlined “1”s denote the carry bits. In decimal arithmetic, 10102 = 1010, 01102 = 610, and 10102 + 01102 = 100002 = 1610. Example 4: 111 1111 + 1011 11010 Recall that 1 + 1 + 1 = 11 in binary. The underlined “1”s denote the carry bits. In decimal arithmetic, 11112 = 1510, 10112 = 1110, and 11112 + 01102 = 110102 = 2610. A final, more complex example performs binary addition on 8-bit numbers. For clarity, groups of 4-bits are written as being separated. Example 5: 1111 111 1011 1111 + 1100 0111 1 1000 0110 In decimal arithmetic, 1011 11112 = 19110, 1100 01112 = 19910, and 1011 11112 + 1100 01112 = 39010,
← Previous Chapter Next Chapter →