6.2.1660 HEX CORE EXT

( -- )

Set contents of BASE to sixteen.

Testing:

ContributeContributions

NieDzejkobavatar of NieDzejkob [46] Suggested reference implementationSuggested reference implementation2018-01-06 18:19:18

: HEX 16 BASE !

alextangentavatar of alextangent

  1. This is not a correct definition; the closing ; is missing.
  2. It will only compile correctly if the 16 is interpreted as a decimal number, which the definition does not ensure.

JimPetersonavatar of JimPeterson

With DECIMAL, you could:

BASE @ DECIMAL : HEX 16 BASE ! ; BASE !

... but then it's difficult to define DECIMAL (without HEX or BIN).

The best I could come up with for the entire set is:

BASE @        \ remember it ...
1 2* BASE !   \ get to binary

: BIN        10 BASE ! ;
: DECIMAL  1010 BASE ! ;
: HEX     10000 BASE ! ;

BASE !        \ ... and restore it

AntonErtlavatar of AntonErtl

Forth-2012 supports number prefixes, so we can define:

: DECIMAL ( -- ) #10 BASE ! ;
: HEX     ( -- ) $10 BASE ! ;

And actually the number prefixes make DECIMAL and HEX mostly superfluous.

BIN is not a word for setting BASE, BTW.

Reply New Version