// Copyright (c) 2026 Charles KWON OhJun (charleskwonohjun@gmail.com) // All rights reserved. // Bit operation functions using Go's native operators. // HB_BITAND, HB_BITOR, HB_BITXOR, HB_BITSHIFT, HB_BITNOT, // HB_BITTEST, HB_BITSET, HB_BITRESET package hbrtl import "five/hbrt" // HB_BITAND(nVal1, nVal2 [, nValN...]) → nResult func HbBitAnd(t *hbrt.Thread) { nParams := t.ParamCount() t.Frame(nParams, 0) defer t.EndProc() result := t.Local(1).AsLong() for i := 2; i <= nParams; i++ { result &= t.Local(i).AsLong() } t.RetLong(result) } // HB_BITOR(nVal1, nVal2 [, nValN...]) → nResult func HbBitOr(t *hbrt.Thread) { nParams := t.ParamCount() t.Frame(nParams, 0) defer t.EndProc() result := t.Local(1).AsLong() for i := 2; i <= nParams; i++ { result |= t.Local(i).AsLong() } t.RetLong(result) } // HB_BITXOR(nVal1, nVal2 [, nValN...]) → nResult func HbBitXor(t *hbrt.Thread) { nParams := t.ParamCount() t.Frame(nParams, 0) defer t.EndProc() result := t.Local(1).AsLong() for i := 2; i <= nParams; i++ { result ^= t.Local(i).AsLong() } t.RetLong(result) } // HB_BITNOT(nVal) → nResult func HbBitNot(t *hbrt.Thread) { t.Frame(1, 0) defer t.EndProc() t.RetLong(^t.Local(1).AsLong()) } // HB_BITSHIFT(nVal, nShift) → nResult // nShift > 0: left shift, nShift < 0: right shift func HbBitShift(t *hbrt.Thread) { t.Frame(2, 0) defer t.EndProc() val := t.Local(1).AsLong() shift := t.Local(2).AsLong() if shift >= 0 { t.RetLong(val << uint(shift)) } else { t.RetLong(val >> uint(-shift)) } } // HB_BITTEST(nVal, nBit) → lSet func HbBitTest(t *hbrt.Thread) { t.Frame(2, 0) defer t.EndProc() val := t.Local(1).AsLong() bit := uint(t.Local(2).AsLong()) t.RetBool((val & (1 << bit)) != 0) } // HB_BITSET(nVal, nBit) → nResult func HbBitSet(t *hbrt.Thread) { t.Frame(2, 0) defer t.EndProc() val := t.Local(1).AsLong() bit := uint(t.Local(2).AsLong()) t.RetLong(val | (1 << bit)) } // HB_BITRESET(nVal, nBit) → nResult func HbBitReset(t *hbrt.Thread) { t.Frame(2, 0) defer t.EndProc() val := t.Local(1).AsLong() bit := uint(t.Local(2).AsLong()) t.RetLong(val &^ (1 << bit)) }