http://www.emu8086.com/assembler_tutorial/numbering_systems_tutorial.html 1. Decimal System
1. Decimal System
Note:
2. Binary System
3. Hexadecimal System
|
4. Converting from decimal system to any other
divide the decimal value by the base of the desired system,
remember the result and keep the remainder,
the divide process continues until the result is zero.
The remainders are then used to represent a value in that system.
EXAMPLES
a. From decimal to hexadecimal
Let's convert the value of 39 (base 10) to Hexadecimal System (base 16):
As you see we got this hexadecimal number: 27h.
All remainders were below 10 in the above example, so we do not use any letters.
Here is another more complex example:
let's convert decimal number 43868 to hexadecimal form:
b. From decimal to binary
Method 1: using 2 as the divider
Method 2: convert to hexadecimal number, and then convert it to binary number:
As you see we got this binary number: 1010101101011100b
5. Signed Numbers
There is no way to say for sure whether the hexadecimal byte 0FFh is positive or negative, it can represent both decimal value "255" and "- 1".
8 bits can be used to create 256 combinations (including zero), so we simply presume that first 128 combinations (0..127) will represent positive numbers and next 128 combinations (128..256) will represent negative numbers.
In order to get "- 5", we should subtract 5 from the number of combinations (256), so it we'll get: 256 - 5 = 251.
Using this complex way to represent negative numbers has some meaning, in math when you add "- 5" to "5" you should get zero.
This is what happens when processor adds two bytes 5 and 251, the result gets over 255, because of the overflow processor gets zero!
When combinations 128..256 are used the high bit is always 1, so this maybe used to determine the sign of a number.
The same principle is used for words (16 bit values), 16 bits create 65536 combinations, first 32768 combinations (0..32767) are used to represent positive numbers, and next 32768 combinations (32767..65535) represent negative numbers.
There are some handy tools in emu8086 to convert numbers, and make calculations of any numerical expressions, all you need is a click on Mathmenu:
Base converter allows you to convert numbers from any system and to any system. Just type a value in any text-box, and the value will be automatically converted to all other systems. You can work both with 8 bit and 16 bit values.
Multi base calculator can be used to make calculations between numbers in different systems and convert numbers from one system to another. Type an expression and press enter, result will appear in chosen numbering system. You can work with values up to 32 bits. When Signed is checked evaluator assumes that all values (except decimal and double words) should be treated as signed. Double words are always treated as signed values, so 0FFFFFFFFh is converted to -1.
For example you want to calculate: 0FFFFh * 10h + 0FFFFh (maximum memory location that can be accessed by 8086 CPU). If you check Signed andWord you will get -17 (because it is evaluated as (-1) * 16 + (-1) . To make calculation with unsigned values uncheck Signed so that the evaluation will be 65535 * 16 + 65535 and you should get 1114095.
You can also use the base converter to convert non-decimal digits to signed decimal values, and do the calculation with decimal values (if it's easier for you).
These operation are supported:
~ not (inverts all bits).
* multiply.
/ divide.
% modulus.
+ sum.
- subtract (and unary -).
<< shift left.
>> shift right.
& bitwise AND.
^ bitwise XOR.
| bitwise OR.
Binary numbers must have "b" suffix, example:
00011011b
Hexadecimal numbers must have "h" suffix, and start with a zero
when first digit is a letter (A..F), example:
0ABCDh
Octal (base 8) numbers must have "o" suffix, example:
77o