← Advanced course and all videos

Video 17 of 53 · 5:36 · Execution, sharing and reuse

Packing truth outputs into bits

In this video

  1. 0:00 · Introduction
  2. 0:17 · Pack the outputs rather than the input labels
  3. 1:20 · Read the hexadecimal spelling
  4. 2:00 · Core explanation
  5. 3:25 · Extract the zero bit rather than a neighboring bit
  6. 4:30 · Negate only the declared universe
  7. 5:25 · Direct takeaways

Caption transcript

Show transcript
This overview explains how ordered Boolean outputs occupy bit positions in an integer or packed word. Confusing assignment order with printed binary order can make a correct value appear reversed or put it in the wrong position. For this packing example, assign bit zero to input zero zero, bit one to zero one, bit two to one zero, and bit three to one one. We pack the output bits of or. The input labels identify positions; they are not the values being packed. Multiply each output by its bit weight. The zero contributes nothing, and the three ones contribute two, four, and eight, totaling fourteen. Written as a binary numeral, the highest bit appears on the left, so the word reads one one one zero. The displayed truth-vector order is still zero one one one. For input one zero, select position two. The four-bit numeral one one one zero shifts right twice to zero zero one one. A mask names the positions to keep: zero zero zero one keeps only the low bit. Pairwise and gives zero and zero, zero and zero, one and zero, and one and one: zero zero zero one. The retrieved answer is one. The retained example uses hexadecimal notation. The prefix zero x marks base sixteen, where the digit E means fourteen. Each hexadecimal digit represents four binary positions. One E E E therefore spells zero zero zero one, then three groups of one one one zero. It is a different spelling of the same number, not a new logical operator. That number is seven thousand nine hundred eighteen in decimal. Its meaning as a truth word still depends on the declared valid width and assignment-to-bit order. Assign each truth output a bit position. For this example, assignments A B C D run from 0000 to 1111; output for assignment index j occupies bit j. Written binary numerals normally print their most significant bit first, so do not confuse that print order with assignment order. First compute A AND B and C OR D, then take the exclusive-or of those results. In ascending assignment order, the outputs are 0111 0111 0111 1000. Packing with bit j assigned to output j gives hexadecimal 0x1EEE. A word array can carry those same bits in lanes. For a toy six-bit result, bitwise NOT must be followed by mask 111111 to discard unused high bits. Packing changes storage and execution layout, not the function. Current direct BitSet evaluation memoizes expression identities and supports fixed bindings; calling it raw unshared AST would misdescribe this implementation. Big integers and machine words need separate measurements before choosing an engine. Return to the four-bit word for F equals A or B. The numeric word is fourteen. Its valid width is four, with inputs zero zero, zero one, one zero and one one assigned to bit positions zero through three. Here A and B are both zero. The numeric word fourteen has its lowest bit clear. Because input zero zero was assigned to bit zero, masking that bit gives zero. Reading bit one instead would give one and would answer the neighboring input zero one. An off-by-one address can produce a plausible but incorrect answer. This case establishes a specific contrast. Bit position comes from the declared order. Packed values still require exact addressing. Keep the input, intermediate values, and conclusion together when comparing it with the previous case. The calculated answer belongs to this complete assignment under the stated rule. The word stores four valid truth outputs. A machine integer may contain many more bit positions, so its full machine-word complement does not by itself identify the valid outputs. Keep the width and the valid-bit mask alongside the data. Complementing and then masking to four bits gives one. In assignment order, that is one zero zero zero, the outputs of not or. The mask removes unused high bits instead of counting them as extra satisfying assignments. With four Boolean inputs, there are sixteen assignments and therefore sixteen outputs to pack. There are not merely four output bits because there are four input variables. Packing can reduce storage overhead, but whether it improves a particular request depends on construction, operations, and output delivery. Declare the assignment-to-bit mapping and requested width. Mask negation to that width and measure engines under the same output contract.