Home > CBM > BASIC > Keywords > Dec
180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Pointer, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor

KeywordAbbreviationToken (hex)Version(s)Classification
DECnoneD13.5,7.0Function
COLLECTCO{Shift+L}D14.xCommand and Statement

 Syntax 
DEC hexadecimal )
 
ParametersTypeLegal Value(s)Default ValueNote(s)
hexadecimalString
1 to 4 hexadecimal digits
spaces are skipped and aren't counted
 
ReturnsTypeValue(s)Note(s)
decimalInteger*
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