EPOC   SDK Home Glossary   Previous Next Up

HEX$HOUR


Contents


HEX$ — Converts an integer to a hex string

Usage:      h$=HEX$(x&)

Returns a string containing the hexadecimal (base 16) representation of integer or long integer x&.

For example HEX$(255) returns the string "FF".


Notes

To enter integer hexadecimal constants (16 bit) put a $ in front of them. For example $FF is 255 in decimal. (Don’t confuse this use of $ with string variable names.)

To enter long integer hexadecimal constants (32 bit) put a & in front of them. For example &FFFFF is 1048575 in decimal.

Counting in hexadecimal is done like this: 0 1 2 3 4 5 6 7 8 9 A B C D E F 10... where A stands for decimal 10, B for decimal 11, C for decimal 12 ... up to F for decimal 15. After F comes 10, which is equivalent to decimal 16. To understand numbers greater than hexadecimal 10, again compare hexadecimals with decimals. In these examples, 102 means 10 × 10, 103 means 10 × 10 × 10 and so on.

253 in decimal is:

(2 × 102)+(5 × 101)+(3 × 100) = (2 × 100)+(5 × 10)+(3 × 1) = 200+50+3

By analogy, &253 in hexadecimal is:

(&2 × 162)+(&5 × 161)+(&3 × 160) =(2 × 256)+(5 × 16)+(3 × 1) =512+80+3 = 595 in decimal.

Similarly, &A6B in hexadecimal is:

(&A × 162)+(&6 × 161)+(&B × 160) =(10 × 256)+(6 × 16)+(11 × 1) =2560+96+11 = 2667 in decimal.

You may also find this table useful for converting between hex and decimal:

hex

decimal

 

&1

1

=160

&10

16

=161

&100

256

=162

&1000

4096

=163

For example, &20F9 is

(2 × &1000)+(0 × &100)+(15 × &10)+9 which in decimal is: (2 × 4096)+(0 × 256)+(15 × 16)+9 = 8441.

All hexadecimal constants are integers ($) or long integers (&). So arithmetic operations involving hexadecimal numbers behave in the usual way. For example, &3/&2 returns 1, &3/2.0 returns 1.5, 3/$2 returns 1.


HOUR — Gets the current hour

Usage:      h%=HOUR

Returns the number of the current hour from the system clock as an integer between 0 and 23.

EPOC       SDK Home Glossary   Previous Next Up