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

DEC

Keyword Abbreviation Token (hex) Version(s) Classification
DEC none D1 3.5,7.0 Function
COLLECT CO{Shift+L} D1 4.x Command and Statement

  Syntax  
DEC hexadecimal )
 
Parameters Type Legal Value(s) Default Value Note(s)
hexadecimal String
1 to 4 hexadecimal digits
spaces are skipped and aren't counted
 
Returns Type Value(s) Note(s)
decimal Integer*
0 to 65535
 
  Purpose  
Return the "normal" decimal value of a number specified as hexadecimal.
 
  Remarks  
The DEC function parses a text string, hexidecimal, as a radix-16 number and returns the "integer" value.  Like most BASIC functions and operators, it actually returns a floating-point "type" of value, however it will always be (mathematically speaking) an integer.  It is unfortunate it won't process fractional values.  Another limitation is it only processes up to 4 characters, so the maximum value ("FFFF") possible to be returned is 65535.  Yet another issue is that many BASIC operations involving integers work with signed integers, but this function can only generate unsigned integers.
 
I won't go into details here, but suffice it to say, a hexadecimal number consists of normal Arabic digits 0 to 9, plus 6 more digits represented by Latin letters A to F.  The hexidecimal number must be specified as a string, otherwise a TYPE MISMATCH ERROR is generated.
 
Unlike the similar VAL function, this one is a cry-baby.  The only non-hexadecimal character allowed is a space.  As stated above, a maximum of four of them is allowed.  Any more digits or non-valid characters generates an ILLEGAL QUANTITY ERROR.  It is handy for quick calculations in direct mode, but it requires the use of an error TRAP routine if you want your program to be robust against data entry errors.
 
Examples:
PRINT DEC("100.8")

?ILLEGAL QUANTITY ERROR 
READY.
PRINT DEC("100")
 256
 
READY.
PRINT DEC(100)

?TYPE MISMATCH ERROR
READY.
 
  Compare With  
 
  Contrast With  
 
  See Also  

© H2Obsession, 2014
Comments