Numbers ..
Decimal Numbers
As several Base notations are used in programming, let us start with a review of what the Base is for Decimal Numbers. When we say that, in Decimal notation, the base is 10, we mean that the computation of a Number is based upon powers of 10, and that each Digit represents a value from 0 to 9. Example: 2,643 Decimal notation may be represented as follow:
(3*10^0) + (4*10^1) + (6*10^2) + (2*10^3)
First clearly understanding how we play with those powers of ten in Decimal Notation makes it much easier to understand HexaDecimal and Binary Notations, as they all may be expressed in the same manner.
Hexadecimal Numbers
Though it is popularly said that Computers are basically 'Binary Systems', the true base of Numbers computing is not at all the Bit (0 or 1). The lowest accessable level for Numbers, either in a Computers Registers or in Memory, is the single byte (8 bits) in Hexadecimal form. Accessing Bits is not the 'natural' way and requires extended manipulative logical efforts.
The Base for HexaDecimal is 16 and one 'Digit' is represented by a Byte, that is, a number ranging from 0 to 15. The smallest direct access to any Memory content or any register content is the Byte size. As we only have ten traditional Digits in Decimal Notation, HexaDecimal is represented by these 10 usual Digits, plus an additional range of letters, from 'A' to 'F':
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
If you see this for the first time, note, for example:
... that 0F + 1 = 010,
... that the maximum value in a Byte is 0FF,
... that if you add 1 to a 0FF Byte, its Value is zeroed,
...and that, in RosAsm syntax, what differentiates the various Notations are the leading zero Digits:
11 > 11 Decimal
011 > 11 Hexa (17 Decimal)
0011 > 11 Binary (3 Decimal)
02643 HexaDecimal notation may be represented as follow:
(3*16^0) + (4*16^1) + (6*16^2) + (2*16^3)
All of the usual Numbers Sizes units are based upon Hexadecimal. The commonly used sizes are:
Byte > 1 Byte > 8 Bits (0_11)
Word > 2 Bytes > 16 Bits (0_2211)
dWord > 4 Bytes > 32 Bits (0_4433_2211)
qWord > 8 Bytes > 64 Bits (0_8877_6655_4433_2211)
Binary Numbers
In the binary number system, based upon powers of 2, the Digits are either 0 or 1.
0_0110_1010 Binary notation may be represented as follow:
(0*2^0) + (1*2^1) + (0*2^2) + (1*2^3) + (0*2^4) + (1*2^5) + (1*2^6)
Accessing Bits, inside the real Hexadecimal of Memory or Registers requires particular indirect masking operations, that can be performed either by some Mnemonics or by masking the values 'by hand':
test eax 00_1000
and B§Memory (not 32)
Hexadecimal in Memory
Say we have an Hexadecimal dWord Value of 0_1122_3344 stored in a File. Then you search for this Value with any Hexadecimal Editor: You will not at first see it. Its real appearance in the dead File Bytes flow will be as this:
xx xx xx 44 33 22 11 xx xx xx
Why are the Byte parts of a dWord Number in the pseudo reverse order? Well, this may seem stupid, at first , but this its really not: Storing the Values this way has the great advantage of allowing the Values accesses with a certain consitency, no matter the accessed size:
Say the upper value is pointed by a symbol as 'Value'. Now, if you do:
mov al B$Value | mov bx W$Value | mov ecx D$Value
al = 044 // bx = 0_3344 // ecx = 0_1122_3344
This is to say that, if you have a qWord Number whose value is 1, stored somewhere, you also may read it either as dWord, Word or Byte, the returned Value will be 1 in all cases. Are you sure you would have preferred it the other way round?
~~~~~~~