Writing a Simple Operating System — from Scratch

(Jeff_L) #1

CHAPTER 2. COMPUTER ARCHITECTURE AND THE BOOT


PROCESS 7


Decimal has a base of ten (i.e. has ten distinct digit symbols), but hexadecimal has
a base of 16, so we have to invent some new number symbols; and the lazy way is just to
use a few letters, giving us:0,1,2,...8,9,a,b,c,d,e,f, where the single digitd, for
example, represents a count of 13.
To distinguish among hexadecimal and other number systems, we often use the prefix
0x, or sometimes the suffixh, which is especially important for hexadecimal digits that
happen not to contain any of the letter digits, for example:0x50does not equal (decimal)
50 ---0x50is actually 80 in decimal.
The thing is, that a computer represent a number as a sequence ofbits(binary digits),
since fundamentally its circuitry can distinguish between only two electrical states: 0 and
1 --- it’s like the computer has a total of only two fingers. So, to represent a number
larger than 1 , the computer can bunch together a series of bits, just like we may count
higher than 9 by having two or more digits (e.g. 456 , 23 , etc.).
Names have been adopted for bit series of certain lengths to make it easier to talk
about and agree upon the size of numbers we are dealing with. The instructions of
most computers deal with a minimum of 8 bit values, which are namedbytes. Other
groupings areshort,int, andlong, which usually represent 16-bit, 32-bit, and 64-bit
values, respectively. We also see the termword, that is used to describe the size of the
maximum processing unit of the current mode of the CPU: so in 16-bit real mode, a
wordrefers to a 16-bit value; in 32-bit protected mode, awordrefers to a 32-bit value;
and so on.
So, returning to the benefit of hexadecimal: strings of bits are rather long-winded to
write out but are much easier to convert to and from the more shorthand hexadecimal
notation than to and from our natural decimal system, essentially because we can break
the conversion down into smaller, 4-bit segments of the binary number, rather than try
to add up all of the component bits into a grand total, which gets much harder for larger
bit strings (e.g. 16, 32, 64, etc.). This difficulty with decimal conversion is shown clearly
by the example given in Figure 2.3.


Figure 2.3: Conversion of 1101111010110110 to decimal and hexadecimal

Free download pdf