11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: Performing Logical Operations 55123 10 = 0*128 + 1*64 + 1*32 + 1*16 + 1*8 + 0*4 +1*2 + 1*1= 01111011 2Computer convention expresses binary numbers by using 4, 8, 16, 32 or even64 binary digits even if the leading digits are zero. This is also because of theway computers are built internally.Because the term digit refers to a multiple of ten, a binary digit is called a bit(an abbreviation of binary digit). Eight bits make up a byte. (Calling a binarydigit a byte-it didn’t seem like a good idea.) A short word is two bytes; a longword is four bytes.With such a small base, you have to use a large number of bits to expressnumbers. Human beings don’t want the hassle of using an expression such as01111011 2 to express such a mundane value as 123 10 . Programmers prefer toexpress numbers by using an even number of bits. The octal system — whichis based on 3 bits — has been almost completely replaced by the hexadecimalsystem, which is based on 4-bit digits.Hexadecimal uses the same digits for the numbers 0 through 9. For the digitsbetween 9 and 16, hexadecimal uses the first six letters of the alphabet: A for10, B for 11, etc. Thus, 123 10 becomes 7B 16 , like this:123 = 7 * 16 1 + B (i.e. 11) * 16 0 = 7B 16Programmers prefer to express hexadecimal numbers in 2, 4, or 8 hexadecimaldigits even when the leading digit in each case is 0.Finally, who wants to express a hexadecimal number such as 7B 16 by using asubscript? Terminals don’t even support subscripts. Even on a word processorsuch as the one I’m using now, it’s a drag to change fonts to and from subscriptmode just to type two lousy digits. Therefore, programmers (no foolsthey) use the convention of beginning a hexadecimal number with a 0x. (Why?Well, the reason for such a strange convention goes back to the early days ofC, in a galaxy far, far, away . . . never mind.) Thus, 7B becomes 0x7B. Usingthis convention, the hexadecimal number 0x7B is equal to 123 decimal while0x123 hexadecimal is equal to 291 decimal.You can use all the mathematical operators on hexadecimal numbers, in thesame way you’d apply them to decimal numbers. (Well, okay, most of us can’tperform a multiplication such as 0xC * 0xE in our heads, but that has moreto do with the multiplication tables we learned in school than it has to dowith any limitation in the number system.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!