factor/library/io/binary.factor

13 lines
395 B
Factor
Raw Normal View History

! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2004-08-18 01:13:56 -04:00
IN: stdio
2005-06-10 16:08:00 -04:00
USING: kernel lists math sequences strings ;
2004-08-18 01:13:56 -04:00
2005-06-10 16:08:00 -04:00
: be> ( seq -- x ) 0 swap [ >r 8 shift r> bitor ] each ;
: le> ( seq -- x ) reverse be> ;
2005-06-10 16:08:00 -04:00
: nth-byte ( x n -- b ) -8 * shift HEX: ff bitand ;
2005-06-10 16:08:00 -04:00
: >le ( x n -- string ) [ nth-byte ] project-with >string ;
: >be ( x n -- string ) >le reverse ;