Sharp logo

The hexadecimal notation 

The hexadecimal ( not well known as sedecimal ) notation is used by most machine language programmers when they talk about a number or address in a machine language program. The hexadecimal numerical system is one of all value-positional numerical systems.

Some assemblers let you refer to addresses and numbers in decimal ( base 10 ), binary ( base 2 ), or even octal ( base 8 ) as well as hexadecimal ( base 16 ) or just "hex" as most people say. These assemblers do the conversions for you.

Each position within a hexadecimal value refers to a base of sixteen.

Hexadecimal probably seems a little hard to grasp at first, but like most things, it won't take long to master with practice.


The hexadecimal numerical sytem uses 16 numbers.


By looking at decimal ( base 10 ) numbers, you can see that each digit falls somewhere in the range between zero and a number equal to the base less one ( e.g. 9 ).

This is true of all number bases.

Binary ( base 2 ) numbers have digits ranging from zero to one ( which is one less than the base ). Similarly, hexadecimal numbers should have digits ranging from zero to fifteen, but we do not have any single digit figures for the numbers ten10 to fifteen10, so the first six letters of the alphabet are used instead ( A, B, C, D, E, and F ).

 
Decimal Hexadecimal Binary
 0
 0
00000000
 1
 1
00000001
 2
 2
00000010
 3
 3
00000011
 4
 4
00000100
 5
 5
00000101
 6
 6
00000110
 7
 7
00000111
 8
 8
00001000
 9
 9
00001001
10
 A
00001010
11
 B
00001011
12
 C
00001100
13
 D
00001101
14
 E
00001110
15
 F
00001111
16
10
00010000
Let's look at it another way; here's an example of how a base 10 ( decimal number ) is constructed:

Base 10 decreasing powers:
103
102
101
100
 
Equals to:
1,000
100
10
1
 
Consider 4,569 ( base 10 )
4
5
6
9
 
Multiply each decimal digit in the 3rd row by its positional value in the 2nd row, and put each multiplication result into the rightmost column. At last sum up all multiplication results within the rightmost column.
     
9
*1=9
   
6
*10=
60
 
5
*100=
500
4
*1,000=
4,000

= 4,569


Now look at an example of how a base 16 ( hexadecimal number ) is constructed:

Base 16 decreasing powers:
163
162
161
160
 
Equals to:
4,096
256
16
1
 
Consider 11D9 ( base 16 )
1
1
D
9
 
Multiply each hexadecimal digit in the 3rd row by its positional value in the 2nd row, and put each multiplication result into the rightmost column. At last sum up all multiplication results within the rightmost column.
     
9
*1=9
   
13
*16=
208
 
1
*256=
256
1
*4,096=
4,096

= 4,569

Therefore, 4,569 ( base 10 ) = 11D9 ( base 16 ).

The range for addressable memory locations of a MZ normally is 0 - 65,535. This range is therefore $0000 - $FFFF in hexadecimal notation.

Usually hexadecimal numbers are prefixed with a dollar sign ( $ ). This is to distinguish them from decimal numbers.

Let's look at some "hex" numbers, using the monitor subprogram of the S-BASIC, by displaying the contents of some memory by typing:

B. ( to invoke the monitor subprogram of the S-Basic ) and next type in:
D6BCF 6BE6. This will display the contents of the memory from $6BCF to $6BE6 ( you can do this by the monitor program 1Z-013A too but in this case omit the command "B.").

Display a part of MZ's memory content

You'll see 3 rows of 9 hex numbers. The first 4-digit is the address of the first byte of memory being shown in that row, and the other eight numbers are the actual contents of the memory locations beginning at that start address.

You should really try to learn to "think" in hexadecimal. It's not too difficult, because you don't have to think about converting it back into decimal. For example, if you said that a particular value is stored at $10F0 instead of 4,336, it shouldn't make any difference.


We've converted a hex number into a decimal number. Now we'll convert a decimal number into a hex number.

To this, use the table at the right. The table shows the result for each positional value.

E.g. $C000 is to compute by:

$C * 164 ( base 16 )
is adequate to
12 * 65,536 = 786,432 ( base 10 ).

You find the base 10 multiplication result 786,432 by crossing the row for $C and the column for its positional value 164.

 
Decimal Hex
powers of 16
164
65,536
163
4,096
162
256
161
16
160
1
1
1
65,536
4,096
256
16
1
2
2
131,072
8,192
512
32
2
3
3
196,608
12,288
768
48
3
4
4
262,144
16,384
1,024
64
4
5
55
327,680
20,480
1,280
80
5
6
6
393,216
24,576
1,536
96
6
7
7
458,752
28,672
1,792
112
7
8
8
524,288
32,768
2,048
128
8
9
9
589,824
36,864
2,304
144
9
10
A
655,360
40,960
2,560
160
10
11
B
720,896
45,056
2,816
176
11
12
C
786,432
49,152
3,072
192
12
13
D
851,968
53,248
3,328
208
13
14
E
917,504
57,344
3,584
224
14
15
F
983,040
61,440
3,840
240
15
 
The decimal number 1,999 is to convert into its hex value. To this we paint a table like this and compute each digit step by step.  
Decimal
number
Hexadecimal number
163
4,096
162
256
161
16
160
1
1,999
          
 
 
 
 
Now find a value in the first table that is less or equal to 1,999 ( I've coloured all values to find during our conversion yellow ). You'll get 1,792 = 7 * 256 = 7 * 162. That means we do not need the column 163 in our table for the result of the conversion but we can put "7" into the column 162.  
Decimal
number
Hexadecimal number
163
4,096
162
256
161
16
160
1
1,999
 
7
 
 
 
We've used 1,792 from 1,999, that means the remainder is 1,999 - 1,792 = 207. Now again we've to find a value in the first table that is less or equal to 207. It is 192 = 12 * 161. We put "C" into the column 161.  
Decimal
number
Hexadecimal number
163
4,096
162
256
161
16
160
1
1,999
 
7
C
 
 
The remainder is 207 - 192 = 15. 15 * 1 = 15 * 160. We put "F" into the column 160. $7CF is the hex value of 1,999 ( base 10 ).  
Decimal
number
Hexadecimal number
163
4,096
162
256
161
16
160
1
1,999
 
7
C
F
50,860
C
6
A
C
     
I've put one more conversion into the table for the decimal number 50,860. Try to do the conversion for this number, if you want.
 

You can test the correct value by converting back the hex value into a decimal value:
 
C
==>
12
*
4,096
==>
49,152
6
==>
6
*
256
==>
1,536
A
==>
10
*
16
==>
160
C
==>
12
*
1
==>
12

           
50,860

It's important to know how to do the conversions like our knowledge about multiplication, addition, substraction, and division. Sure, we do all mostly by an electronic calculator. All these conversions can be done by an electronic calculator too.

Be sure your browser is able to run JavaScript and Java and then click here to try an electronic calculator written in the Java language. It takes some time until all Java classes will be transferred to your PC, please wait.

You can download this electronic calculator now ( 72KB ) if you want.

That's it. Next will be to convert a binary number into a hex number and vice versa.

Go to the top of this page Home

last updated August 19, 2002
sharpmz@sharpmz.org

khmweb barrierefreies webdesign Berchtesgaden