Handbook
Glossary
bit-range ( x high low -- y )
Factor handbook
»
The language
»
Numbers
»
Arithmetic
»
Bitwise arithmetic
»
Additional bitwise arithmetic
Prev:
bit? ( x n -- ? )
Next:
bits ( m n -- m' )
Vocabulary
math
.
bitwise
Inputs
x
an
integer
high
an
integer
low
an
integer
Outputs
y
an
integer
Word description
Extract a range of bits from an integer, inclusive of each boundary.
USING: math.bitwise prettyprint ; 0b1100 3 2 bit-range .b
0b11
Definition
USING:
combinators.short-circuit
kernel
math
;
IN:
math.bitwise
:
bit-range
( x high low -- y )
2dup
{
[
nip
0
<
]
[
<
]
}
2||
[
bit-range-error
]
when
[
nip
neg
shift
]
[
-
1
+
]
2bi
bits
;
inline