bit-test?

test-val bit-pos


Summary

Test bit at position i

Description

We check if test-val has a 1 at bit-pos and return #t if that is the case

Arguments

test-val
The integer in which to look for the bit
bit-pos
Which bit to look for, with 0 being the least significant digit

Return value

A boolean signifying whether the bit is set or not

Examples

(bit-test? 9 7)
#f

(bit-test? 9 1)
#f

(bit-test? 9 0)
#t

Bytecode

Probably only interesting to you if you want to understand more about the Nujel VM or care very much about performance.

(    0 ($get/val 'type-of))
(    2 ($get/val 'test-val))
(    4 ($apply 1))
(    6 ($push/val :int))
(    8 ($=))
(    9 ($jf* 7))
(   12 ($push/nil))
(   13 ($jmp* 21))
(   16 ($get/val 'throw))
(   18 ($get/val 'list))
(   20 ($push/val :type-error))
(   22 ($push/val Expected a value of type :int))
(   24 ($get/val 'test-val))
(   26 ($get/val 'current-lambda))
(   28 ($apply 0))
(   30 ($apply 4))
(   32 ($apply 1))
(   34 ($drop))
(   35 ($get/val 'type-of))
(   37 ($get/val 'bit-pos))
(   39 ($apply 1))
(   41 ($push/val :int))
(   43 ($=))
(   44 ($jf* 7))
(   47 ($push/nil))
(   48 ($jmp* 21))
(   51 ($get/val 'throw))
(   53 ($get/val 'list))
(   55 ($push/val :type-error))
(   57 ($push/val Expected a value of type :int))
(   59 ($get/val 'bit-pos))
(   61 ($get/val 'current-lambda))
(   63 ($apply 0))
(   65 ($apply 4))
(   67 ($apply 1))
(   69 ($drop))
(   70 ($get/val 'bit-and))
(   72 ($get/val 'test-val))
(   74 ($get/val 'bit-shift-left))
(   76 ($push/int/byte 1))
(   78 ($get/val 'bit-pos))
(   80 ($apply 2))
(   82 ($apply 2))
(   84 ($zero?))
(   85 ($jf* 7))
(   88 ($push/false))
(   89 ($jmp* 4))
(   92 ($push/true))
(   93 ($ret))