Number Systems: Binary and Hexadecimal Tom Brennan
Total Page:16
File Type:pdf, Size:1020Kb
Number Systems: Binary and Hexadecimal Tom Brennan Base 10 The base 10 number system is the common number system. 612 = 2 · 100 + 1 · 101 + 6 · 102 2 + 10 + 600 = 612 4365 = 5 · 100 + 6 · 101 + 3 · 102 + 4 · 103 5 + 60 + 300 + 4000 = 4365 Binary 101010101 = 1 · 20 + 0 · 21 + 1 · 22 + 0 · 23 + 1 · 24 + 0 · 25 + 1 · 26 + 0 · 27 + 1 · 28 = 341 1 + 0 + 4 + 0 + 16 + 0 + 64 + 0 + 256 = 341 The binary number system employs only two digits{0 and 1{and each digit is called a bit. A number can be represented in binary by a string of bits{each bit either a 0 or a 1 multiplied by a power of two. For example, to represent the decimal number 15 in binary you would write 1111. That string stands for 1 · 20 + 1 · 21 + 1 · 22 + 1 · 23 = 15 (1 + 2 + 4 + 8 = 15) History Gottfried Leibniz developed the modern binary system in 1679 and drew his inspiration from the ancient Chinese. Leibniz found a technique in the I Ching{an ancient chinese text{that was similar to the modern binary system. The system formed numbers by arranging a set of hexagrams in a specific order in a manner similar to modern binary. The systems base two nature was derived from the concepts of yin and yang. This system is at least as old as the Zhou Dynasty{it predates 700 BC. While Leibniz based his system of the work of the Chinese, other cultures had their own forms of base two number systems. The Ancient Egyptians employed a type of base two number system called Horus-Eye fractions for their measurements of grain or liquids. The system used sums of binary fractions{which were , , , 1/16, 1/32, and 1/64{to represent fractions of hekats, which were the primary unit of measure in Ancient Egypt and equal to about 4.8 liters. Horus-Eye fractions were in use prior to 1200 BC. Ancient Egyptian multiplication also operated with a system similar to that of the binary number system. The Ancient Indians also had a form of binary. Its purpose differed from those of China and Egypt in that it was meant to describe poetic metre. It was created by the scholar Pingala in about 150 BC, and its duality was derived from describing syllables as either short or long. Applications Binary is used extensively in computer science and telecommunications. It usefulness is derived from the fact that only two digits are required, so a computer can represent the digit 1 with an electrical signal or 0 with no electric signal. The American Standard Code for Information Exchange is used to represent text and symbols within computer memory. It employs seven digit binary strings{which can represent values between 0 and 127(as 26 + 25 + 24 + 23 + 22 + 21 + 20 = 127). Each symbol is represented by a value between 0 and 127. The lower case letter "b", for example,is assigned the number 98 represented by the bit string 1100010 in the ASCII system. Eventually, extended ASCII sets would be released by different computer companies{such as IBM{where data would be processed in 8 bit strings called bytes. The addition of an 8th bit increases the number of possible values excluding 0 from 127 to 255 (because 27 = 128 and 128+127=255). The Braille alphabet also relies on a binary system{because in each position a dot can either be raised from the page or not raised from the page. Information in Braille is organized into cells{rectangular blocks with tiny bumps called raised dots. Each cell has two columns and 3 rows, and there are 63 different cells in braille if you do not count the space. Morse code can be transmitted as a binary code. Telegraph operators send electrical pulses along a telegraph wire, and the presence of a pulse{the on state{represents a one while the absence of a pulse{the off state{ represents a 0. A bit string of 1 represents a short mark, 111 represents a longer mark, 0 represents the gap between the dots and dashes within a character, 000 represents the gap between letters, and 0000000 represents the gap between words. The gray code{also known as the reflected binary code{is a form of binary number system that is employed in color television and bar code scanners. It was first created to address a specific problem with the binary number system that is encountered when using physical switches. In many instances consecutive numbers do not share common digits in their binary representations. The quintessential example of this occurs with the numbers three and four. Three is represented by 011 and four is represented by 100. To switch from three to four all three switches must change state, and it is very unlikely that they all three changes will occur at the exact same time. This can lead to some ambiguity when transmitting codes, as it may be difficult to tell when switches are displaying a position or an intermediate between two positions. Gray code differs from the traditional binary systems by only changing one switch at a time. Gray codes have been extremely useful in the field of telegraphy{Emile Baudot received the French Legion of Honor medal for his work in telegraphy with Gray codes in 1878. However, they were made famous and named for Frank Gray, who figured out how to use a machine called the "PCM tube" to convert analog signals to gray codes in 1953{this method was key in the development of color television. Binary Addition Binary addition functions in a manner very similar to decimal addition. However, instead of carrying a one every time two digits add to 10 or a value greater than 10, a one is carried every time two digits add up to 2 or greater(this could only occur if both binary digits were one and a one is carried from the addition of the previous digits. 1010+1111 First Column: 0+1 =1 2 Second Column: 1+1=0 (one will be carried) Third Column: 0+1+1 (the carried one)=0 (another one will be carried) Fourth Column: 1+1+1(carried one)=1 (one will be carried) Fifth Column: 0+0+1(the carried one)=1 So the sum 1010+1111 is 11001. An easy way to verify this result is to convert the three binary numbers to decimal numbers. The binary number 1010 converts to 10 (1 · 23 + 1 · 21 = 10) The binary number 1111 converts to 15 (1 · 23 + 1 · 22 + 1 · 21 + 1 · 20 = 15) The binary number 11001 converts to 25 (1 · 24 + 1 · 23 + 1 · 20 = 25) It is easy to verify that 10 + 15 = 25 Binary Subtraction Binary subtraction is more complicated than binary addition due to the fact that borrowing is often necessary in binary subtraction. Borrowing in binary is similar to borrowing in decimal, but instead of borrowing a 1 · 101 you borrow a 1 · 21. This can get complicated when you have to borrow from a 0 or multiple 0s, like when subtracting 111 from 1000. In situations like these it may be simpler to convert to decimal and then subtract. For that example the difference is one (8-7=1). Pattern recognition can also be useful. 100-11=1, 10000-1111=1, and 100000-11111=1, or in more general terms, the difference between a string with a one followed by n zeroes and a string of n ones is 1. 10101-1111 First Column: 1-1=0 Second Column: 0-1 (in this instance it is necessary to borrow) 10-1=1 After borrowing in the second column the remaining three digits of the larger number are 100. 100-11=1. So difference between 10101-1111= 110. We can verify this result through decimal subtraction. 21 (24+22+20 = 21) - 15 (23 + 22 + 21 + 20) = 6 (22 + 21 = 6) Most computers use a method called the complement method to subtract binary numbers. The method has five steps. The first is to add zeros to the end of the smaller binary string if necessary to ensure that the two strings have the same number of bits. The second step is to switch all digits in the second term{all zeros should be switched to ones and all ones switched to zeros. The third step is to add one to the new second term. The fourth step is to add the the two terms together. And the fifth and final step is to discard the first term{as there will be an extra digit. 10101-1111 10101 01111 { 3 complement of second string: 10000 add one to second string: 10001 addition of the two strings 10101+10001=100110 discard the first digit 00110 Binary Multiplication Like binary addition, binary multiplication is very similar to decimal multiplication. The main difference between the two is that when adding up the results of the multiplication{in the same manner as decimal multiplication{a one is carried when the digits add to two or greater instead of ten or greater. 1010 1111 x |1010 {1010 -1010 1010 + 10010110 This in decimal converts to 150 (27 + 24 + 22 + 21 = 150) We can verify that this multiplication is correct easily. 1010 in decimal is 10 and 1111 in decimal is 15. 15 ∗ 10 = 150 Hexadecimal The Hexadecimal number system employs sixteen digits: 0-9 represent themselves and then 10-15 are repre- sented by a,b,c,d,e, and f. To differentiate hexadecimal numbers from decimal numbers the can be written with subscripts.