2020-10-28 18:06:58 -04:00
|
|
|
: _pb ( a -- n f, parse binary )
|
|
|
|
( '0': ASCII 0x30 'b': 0x62 0x6230 )
|
|
|
|
DUP 1+ @ 0x6230 = NOT IF 0 EXIT THEN ( a 0 )
|
|
|
|
( We have "0b" prefix )
|
2020-09-21 14:40:53 -04:00
|
|
|
DUP C@ ( a len )
|
|
|
|
0 SWAP 1+ ( len+1 ) 3 DO ( a r )
|
2020-10-28 20:29:28 -04:00
|
|
|
OVER I + C@ ( a r c )
|
|
|
|
DUP '0' '1' =><= NOT IF 2DROP 0 UNLOOP EXIT THEN
|
|
|
|
'0' - SWAP 1 LSHIFT + ( a r*2+n ) LOOP
|
2020-09-21 14:40:53 -04:00
|
|
|
NIP 1 ;
|