move signed-le> to io.binary, clean up using list for math.bitwise
parent
bad8e05937
commit
78bbf96a6d
|
@ -1,8 +1,7 @@
|
|||
! Copyright (C) 2007, 2008 Slava Pestov, Doug Coleman.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: arrays assocs kernel math sequences accessors
|
||||
math.bits sequences.private words namespaces macros
|
||||
hints combinators fry io.binary combinators.smart ;
|
||||
USING: arrays assocs combinators combinators.smart fry kernel
|
||||
macros math math.bits sequences sequences.private words ;
|
||||
IN: math.bitwise
|
||||
|
||||
! utilities
|
||||
|
@ -104,14 +103,6 @@ PRIVATE>
|
|||
: bit-count ( x -- n )
|
||||
dup 0 < [ bitnot ] when (bit-count) ; inline
|
||||
|
||||
! Signed byte array to integer conversion
|
||||
: signed-le> ( bytes -- x )
|
||||
[ le> ] [ length 8 * 1 - on-bits ] bi
|
||||
2dup > [ bitnot bitor ] [ drop ] if ;
|
||||
|
||||
: signed-be> ( bytes -- x )
|
||||
<reversed> signed-le> ;
|
||||
|
||||
: >signed ( x n -- y )
|
||||
2dup neg 1 + shift 1 = [ 2^ - ] [ drop ] if ;
|
||||
|
||||
|
|
|
@ -24,3 +24,10 @@ IN: io.binary
|
|||
: h>b/b ( h -- b1 b2 )
|
||||
[ mask-byte ]
|
||||
[ -8 shift mask-byte ] bi ;
|
||||
|
||||
: signed-le> ( bytes -- x )
|
||||
[ le> ] [ length 8 * 1 - 2^ 1 - ] bi
|
||||
2dup > [ bitnot bitor ] [ drop ] if ;
|
||||
|
||||
: signed-be> ( bytes -- x )
|
||||
<reversed> signed-le> ;
|
||||
|
|
Loading…
Reference in New Issue