Assembly Language StepbyStep Programming with DOS and Linux 2nd Ed [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Assembly Language StepbyStep Programming with DOS and Linux 2nd Ed [Electronic resources] - نسخه متنی

Jeff Duntemann

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید









Hexadecimal: Solving the Digit Shortage


Octal is unlikely to be of use to you unless you do what a friend of mine did and restore an ancient DEC PDP8 computer that he had purchased as surplus from his university, by the pound. (He said it was considerably cheaper than potatoes, if not quite as easy to fry. Not quite.) As I mentioned earlier, the real numbering system to reckon with in the microcomputer world is base 16, which we call hexadecimal, or (more affectionately) simply "hex."

Hexadecimal shares the essential characteristics of any number base, including both Martian and octal: It is a columnar notation, in which each column has a value 16 times the value of the column to its right. It has 16 digits, running from 0 to…what?

We have a shortage of digits here. From zero through nine we're in fine shape. However, 10, 11, 12, 13, 14, and 15 need to be expressed in single digits. Without any additional numeric digits, the people who developed hexadecimal notation in the early 1950s borrowed the first six letters of the alphabet to act as the needed digits.

Counting in hexadecimal, then, goes like this: 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, and so on. Table 2.5 restates this in a more organized fashion, with the decimal equivalents up to 32.














































































































Table 2.5: Counting in Hexadecimal, Base 16


HEXADECIMAL NUMERALS


PRONUNCIATION (FOLLOW WITH "HEX")


DECIMAL EQUIVALENT


0


Zero


0


1


One


1


2


Two


2


3


Three


3


4


Four


4


5


Five


5


6


Six


6


7


Seven


7


8


Eight


8


9


Nine


9


A


A


10


B


B


11


C


C


12


D


D


13


E


E


14


F


F


15


10


Ten (or, One-oh)


16


11


One-one


17


12


One-two


18


13


One-three


19


14


One-four


20


15


One-five


21


16


One-six


22


17


One-seven


23


18


One-eight


24


19


One-nine


25


1A


One-A


26


1B


One-B


27


1C


One-C


28


1D


One-D


29


1E


One-E


30


1F


One-F


31


20


Twenty (or, Two-oh)


32


One of the conventions in hexadecimal which I favor is the dropping of words such as eleven and twelve that are a little too tightly bound to our decimal system and only promote gross confusion. Confronted by the number 11 in hexadecimal (usually written 11H to let us know what base we're speaking), we would say, "one-one hex." Don't forget to say "hex" after a hexadecimal number, again to avoid gross confusion. This is unnecessary with the digits 0 through 9, which represent the exact same values in both decimal and hexadecimal.

Some people still say things like "twelve hex," which is valid, and means 18 decimal. But I don't care for it, and advise against it. This business of alien bases is confusing enough without giving the aliens Charlie Chaplin masks. Each column in the hexadecimal system has a value 16 times that of the column to its right. (The rightmost column, as in any number base, is the units column and has a value of 1.) As you might imagine, the values of the individual columns go up frighteningly fast as you move from right to left. Table 2.6 shows the values of the first seven columns in hexadecimal. For comparison's sake, note that the seventh column in decimal notation has a value of 1 million, while the seventh column in hexadecimal has a value of 16,777,216.
































Table 2.6: Hexadecimal Columns as Powers of 16


HEXADECIMAL


POWER OF 16


DECIMAL


1H


= 160 =


1 × 16 = 10H


10H


= 161 =


16 × 16 = 100H


100H


= 162 =


256 × 16 = 1000H


1000H


= 163 =


4096 × 16 = 10000H


10000H


= 164 =


65536 × 16 = 100000H


100000H


= 165 =


1048576 × 16 = 1000000H


1000000H


= 166 =


16777216 etc…


To help you understand how hexadecimal numbers are constructed, I've dissected a middling hex number in Figure 2.3, in the same fashion that I dissected numbers earlier in both Martian base fooby, and in octal, base 8. Just as in octal, zero holds a place in a column without adding any value to the number as a whole. Note in Figure 2.3 that there are 0, that is, no, 256s present in the number 3C0A9H.


Figure 2.3: The anatomy of 3C0A9H.

As in Figure 2.2, the decimal values of each column are shown beneath the column, and the sum of all columns is shown in both decimal and hex. (Note the subscripts!)


/ 166