Skip to content

Instantly share code, notes, and snippets.

@zeroflag
Created November 13, 2022 22:28
Show Gist options
  • Save zeroflag/68cab6f9aae9c07a4b4e199d122a31c6 to your computer and use it in GitHub Desktop.
Save zeroflag/68cab6f9aae9c07a4b4e199d122a31c6 to your computer and use it in GitHub Desktop.
: hexchr>n ( chr -- n )
48 over 57 between? if 48 - exit then
65 over 70 between? if 55 - exit then
97 over 102 between? if 87 - exit then
-1 ;
: hexstr>n ( adr len -- n )
0 >r
begin
dup 0 >
while
1 - ( len )
r> 4 lshift >r ( acc )
over c@ hexchr>n ( digit )
r> + >r ( acc )
swap 1 + swap ( address )
repeat
2drop r> ;
: 0x ( <word> -- n ) word hexstr>n ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment