Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

HEX$

Keyword Abbreviation Token (hex) Version(s) Classification
HEX$ H{Shift+E} D2 3.5, 7.0 Function
BACKUP BA{Shift+C} D2 4.x Command and Statement

  Syntax  
HEX$ number )
 
Parameters Type Legal Value(s) Default Value Note(s)
number Unsigned Integer
0 to 65535
 
Returns Type Value(s) Note(s)
hexString String
4 characters
 
 
  Purpose  
Return a string containing a hexadecimal represention of the give number.

 
  Remarks  
The HEX$ function conceptually performs decimal to hexadecimal conversion.  As you probably know, the computer works with binary numbers in reality.  Anyway, the given number is used to generate a 4-character hexString.  Unlike the similar STR$ function, this one is a cry-baby; HEX$ has a very limited domain and the result will often include leading zeros.
 
You will get TYPE MISMATCH ERROR with a string expression or variable given for the number (the VAL function may help).  A floating-point number will be converted to an integer (see INT).  An ILLEGAL QUANTITY ERROR is generated if the number is not a Legal Value (see table above).
  
Examples:
PRINT HEX$("65")

?TYPE MISMATCH ERROR 
READY.
PRINT HEX$(65)
0041

READY.
PRINT CHR$(65.6)
0041

READY.
PRINT CHR$(-65.6)

?ILLEGAL QUANTITY ERROR
READY.
PRINT CHR$(65E6)

?ILLEGAL QUANTITY ERROR
READY.
  
  Compare With  
 
  Contrast With  
ASC, DECINSTRLENVAL 
 
  See Also  

© H2Obsession, 2014
Comments