-
Notifications
You must be signed in to change notification settings - Fork 2
The Word API
Florian Wörister edited this page Oct 10, 2025
·
2 revisions
The Word class provides a convenient abstraction for working with fixed-size binary words. It supports standard arithmetic and logical operations, seamless handling of two’s complement representation, and easy conversion between binary and decimal forms. By encapsulating low-level bit manipulations, Word enables developers to perform precise binary computations while keeping code clear and expressive.
This document gives a short introduction on how to work with Word objects.
import {Word} from "@/architectures/emulator";
let w1 = Word.fromSignedIntValue(-1, 8);
let w2 = Word.fromSignedIntValue(5, 8);
let w3 = Word.fromString("00001111", 8);
console.log(w1.toBitString()); // 11111111
console.log(w2.toBitString()); // 00000101
console.log(w3.toBitString()); // 00001111import {Word} from "@/architectures/emulator";
let w = Word.fromString("11111111", 8)
console.log(w.toSignedIntValue()); // -1
console.log(w.toUnsignedIntValue()); // 255import {Word} from "@/architectures/emulator";
let w4 = Word.fromSignedIntValue(32, 8);
let w5 = Word.fromSignedIntValue(12, 8);
let result = w4.add(w5);
console.log(result.toSignedIntValue()); // 44
// Since Word objects are immutable, the add operation does not
// modify the current instance. Instead, it returns a new Word object
// representing the result.
console.log(result === w4); // false
console.log(result === w5); // false