Page 26 - ARM 64 Bit Assembly Language
P. 26
Introduction 9
In base ten, we think of numbers as strings of the ten digits, “0” through “9”. Each digit
counts 10 times the amount of the digit to its right. If we restrict ourselves to integers, then
the digit furthest to the right is always the ones digit. It is also referred to as the least signif-
icant digit. The digit immediately to the left of the ones digit is the tens digit. To the left of
that is the hundreds digit, and so on. The leftmost digit is referred to as the most significant
digit. The following equation shows how a number can be decomposed into its constituent
digits:
0
4
1
2
3
57839 10 = 5 × 10 + 7 × 10 + 8 × 10 + 3 × 10 + 9 × 10 .
Note that the subscript of “10” on 57839 10 indicates that the number is given in base
ten.
Imagine that we only had seven digits: 0, 1, 2, 3, 4, 5, and 6. We need ten digits for base ten.
If we only have seven digits, then we are limited to base seven. In base seven, each digit in
the string represents a power of seven rather than a power of ten. We can represent any integer
in base seven, but it may take more digits than in base ten. Other than using a different base
for the power of each digit, the math works exactly the same as for base ten. For example,
suppose we have the following number in base seven: 330425 7 . We can convert this number
to base ten as follows:
2
3
1
5
4
330425 7 = 3 × 7 + 3 × 7 + 0 × 7 + 4 × 7 + 2 × 7 + 5 × 7 0
= 50421 10 + 7203 10 + 0 10 + 196 10 + 14 10 + 5 10
= 57839 10
Base two, or binary is the “native” number system for modern digital systems. The reason for
this is mainly because it is relatively easy to build circuits with two stable states: on and off
(or 1 and 0). Building circuits with more than two stable states is much more difficult and ex-
pensive, and any computation that can be performed in a higher base can also be performed
in binary. The least significant (rightmost) digit in binary is referred to as the least signifi-
cant bit, or LSB, while the leftmost binary digit is referred to as the most significant bit,or
MSB.
1.3.2 Base conversion
The most common bases used by programmers are base two (binary), base ten (octal), base
ten (decimal), and base sixteen (hexadecimal). Octal and hexadecimal are common because,
as we shall see later, they can be translated quickly and easily to and from base two, and
are often easier for humans to work with than base two. Note that for base 16, we need 16