@abaplint/runtime
Version:
Transpiler - Runtime
26 lines • 856 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBit = getBit;
/* eslint-disable no-bitwise */
const types_1 = require("../types");
function getBit(number, hex, output) {
const byteIndex = Math.floor((number.get() - 1) / 8);
const bitIndex = (number.get() - 1) % 8;
if (hex instanceof types_1.HexUInt8) {
let int = hex.getOffsetRaw(byteIndex);
int >>= (8 - bitIndex - 1);
int &= 1;
// @ts-ignore
output.set(int);
}
else {
if (bitIndex < 0) {
throw new Error("BIT_OFFSET_NOT_POSITIVE");
}
const h = hex.get().substr(byteIndex * 2, 2);
const parsed = parseInt(h, 16).toString(2);
const bits = parsed.padStart(8, "0");
output.set(bits.substr(bitIndex, 1));
}
}
//# sourceMappingURL=get_bit.js.map