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 |
| 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 |
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 | |
Return the "normal" decimal value of a number specified as hexadecimal. 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.
|
© H2Obsession, 2014 |