Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 line
480B

  1. ( returns negative value on error )
  2. : _ ( c -- n )
  3. DUP '0' '1' =><= IF '0' - EXIT THEN
  4. DROP -1 ( bad )
  5. ;
  6. : _pb ( a -- n f, parse binary )
  7. ( '0': ASCII 0x30 'b': 0x62 0x6230 )
  8. DUP 1+ @ 0x6230 = NOT IF 0 EXIT THEN ( a 0 )
  9. ( We have "0b" prefix )
  10. DUP C@ ( a len )
  11. 0 SWAP 1+ ( len+1 ) 3 DO ( a r )
  12. OVER I + C@ ( a r c ) _ ( a r n )
  13. DUP 0< IF 2DROP 0 UNLOOP EXIT THEN
  14. SWAP 1 LSHIFT + ( a r*2+n ) LOOP
  15. NIP 1 ;