Blitz3D+ Command Reference

Hex$ ( value )

Parameters

value - the integer to convert

Description

Converts an integer into a hexadecimal string.

The result is always eight uppercase digits, zero padded, with no "0x" or "$" prefix: Hex( 255 ) is "000000FF" and Hex( -1 ) is "FFFFFFFF". Because the width is fixed you never need to pad it yourself for a debug display, and if you want it shorter, take the last few characters with Right.

Hex earns its keep with colours and bit flags. A packed RGB value printed as hex is instantly readable against the values you typed into your art tool, and a flags word in hex shows you exactly which bits are set. It is also the friendliest way to dump a byte you read from a file or a bank while working out a format.

There is no matching "unhex" command, but you can read a hex literal directly in source by prefixing it with a dollar sign, as in $FF00FF.

See also: Bin, Str, Right, And.

Example

; Hex Example
; -----------

; Hex$ converts an integer to its hexadecimal (base 16) text form,
; always 8 digits - the same notation as $ literals in source code.

Print "Hex$(10)    = "+Hex$(10)+"  (A is 10 in hex)"
Print "Hex$(255)   = "+Hex$(255)
Print "Hex$(4096)  = "+Hex$(4096)
Print "Hex$(65535) = "+Hex$(65535)
Print "Hex$(-1)    = "+Hex$(-1)+"  (all 32 bits set)"

Print ""

; Hex is the natural way to read packed colour values: $RRGGBB
orange=$FF8000
Print "The colour literal $FF8000 is "+orange+" in decimal"
Print "Hex$ makes it readable again: "+Hex$(orange)

Print ""
Print "Press any key to close the example"
WaitKey

End

Index