As the matter of fact hexadecimal and octal number systems play such a huge role only because of algorithms of Tamed Dragon. Machine computes exclusively "in binary" inside. Hexadecimal (or octal, on DEC's machines) number system enables to write short numbers instead of long sequences of zeroes and ones, which makes hackers' life more interesting. These systems are the middle point between machine and human, between binary and decimal number systems.
The role of number systems is very great. For example, file access rights in UNIX system are changed from shell with chmod command. This command demands an argument of access rights in octal! So command
chmod 666 /etc/passwd
opens full read-write access to every user to the passwords file in UNIX system. As you see now, even the most stupid sysadmins must be aware of octal number system. Let alone hackers!
In various programming languages digits in these systems are written differently. Here is the table for the most common languages:
+-------------+-------+--------+--------+----------------+ | | C/C++ | Pascal | BASIC | Assembler | +-------------+-------+--------+--------+--------+-------+ | DECimal | 12 | 12 | 12 | 12,12d | 12T | | HEXadecimal | 0xC | $C | &hC | 0Ch | | | OCTal | 014 | ¥â | &o14 | 14o | 14Q | | BINary | ¥â | ¥â | &b1100 | 1100b | 1100Y | +-------------+-------+--------+--------+--------+-------+
In B1:1 we noted that trailing zeroes do not influence number's value. Creators of C language decided in another way. As no one in his right mind will start the number with zero -- who wants to type unneeded zeroes, zero in the beginning is used for octal number representation.
In every mode of notation the case of the letters is not important. Even case-sensitive C allows to start hexadecimal numbers with 0x as well as with 0X. BTW, guru of Kiev Center of our school said that in early versions of C-compilers of different firms one had to start hexadecimal number with 0x0, else they made glitces.
If hexadecimal number starts with the letter during programming in assembly language, one must always put zero in front of it else assembler will think that you meant Ch variable and not a number C_16. Some persons with not so high IQ, who are unable to accomodate this rule, put zero in front of every number. The worst thing is when such people start to write text-books...
[IBM PC teaching on]
Suffixes T, Q and Y are introduced into MASM assembler relatively recently. The thing is that with the help of .RADIX directive assembler allows to change the default number system. Earlier then, when the number system was being changed to decimal, the numbers like 12D that look like hexadecimal were interpreted as 12_10. This produced the web of small unnoticeable psychodelic errors, that disallowed novices to use .RADIX 16.
[IBM PC teaching off]
We will use all the methods of numbers notation, using assembler-style as primary. You must know it very well because it is being used extensively in technical discussions over the net.
>>>
Functions HEX$, BIN$ and OCT$ are used for conversion from decimal number system to hexadecimal, binary and octal ones in BASIC.
To convert the numbers from this systems to decimal one you should use the trick
?VAL("&hFC")
<<<
<<<B1:6 EOF>>>