🔌
nand2tetris
  • Introduction
  • Combinational Chips
    • Nand Gate
    • Not Gate
    • And Gate
    • Or Gate
    • Xor Gate
    • Multiplexor Chip
    • Demultiplexor Chip
    • Not16 Chip
    • And16 Chip
    • Or16 Chip
    • Mux16 Chip
    • Or8Way Chip
    • Mux4Way16 Chip
    • Mux8Way16 Chip
    • DMux4Way Chip
    • DMux8Way Chip
    • Half Adder Chip
    • Full Adder Chip
    • Add16 Chip
    • Inc16 Chip
    • Half Subtractor Chip
    • Full Subtractor Chip
    • Subtract16 Chip
    • Dec16 Chip
    • Arithmetic Chip
    • ALU
  • Misc
    • Int2Bool
    • Bool2Int
    • Arrayto16
Powered by GitBook
On this page
  1. Misc

Bool2Int

Misc is a package in Java™ Implementation of nand2tetris. It contains basic utilites and reusable codes for creation and modification of chips and its outputs.

Bool2Int Method in class Convert

Input: Boolean

Output: Integer

    public static int Bool2Int(boolean bool) {
        int value;
        if (bool) {
            value = 1;
        } else {
            value = 0;
        }
        return value;
    }

Unlike most programming languages, Java treats boolean and integer data types unusually. However, some of the implemented gates needs to convert back to binary values after conversion to boolean. Therefore, a method Bool2Int is created to convert boolean values (true and false) to binary integral values (0 and 1) for faster computations.

PreviousInt2BoolNextArrayto16

Last updated 3 years ago