Skip to content

Commit cae2d79

Browse files
Expand unsigned-int demo tape to cover all four sizes with 47 commands
Walks through 4, 8, 16, and 32-bit representations exercising every operation: set/random/clear, set-bit/reset-bit/toggle-bit, set-octal/ set-hex, shl/shr/rol/ror (including overflow), not, and/or/xor with binary-octal-hex constants, dec/bin/oct/hex display, save/load/undo/redo. Captioned throughout; ends by reloading the saved 8-bit session from 32-bit. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b338a88 commit cae2d79

1 file changed

Lines changed: 183 additions & 41 deletions

File tree

demos/unsigned-int.tape

Lines changed: 183 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,80 @@ Type ".venv/bin/python -m data_structures.tui.unsigned_int_app"
2020
Enter
2121
Sleep 4s
2222

23-
# ── Set a known value ────────────────────────────────────────────────────────
24-
# CAPTION: Set the byte to 85 — alternating 0s and 1s in binary
25-
Type "/set 85"
23+
# ════════════════════════════════════════════════════════════════════════════
24+
# 4-BIT section
25+
# ════════════════════════════════════════════════════════════════════════════
26+
27+
# CAPTION: Start with a 4-bit integer — the smallest supported size
28+
Type "/size 4"
29+
Enter
30+
Sleep 2s
31+
32+
# CAPTION: Set the value using a binary literal — 0b1010 is decimal 10
33+
Type "/set 0b1010"
2634
Enter
2735
Sleep 2s
2836

29-
# ── Explore hex and octal groupings ─────────────────────────────────────────
30-
# CAPTION: Show the value — binary 01010101, hex 0x55, octal 125
37+
# CAPTION: Show the value in all four bases at once
3138
Type "/show"
3239
Enter
3340
Sleep 2s
3441

35-
# ── Bit-level manipulation ───────────────────────────────────────────────────
36-
# CAPTION: Set bit 7 (the MSB) to 1 — value jumps to 213
42+
# CAPTION: Set bit 0 (the LSB) — value becomes 11
43+
Type "/set-bit 0"
44+
Enter
45+
Sleep 2s
46+
47+
# CAPTION: Toggle bit 3 (the MSB) from 1 to 0 — value becomes 3
48+
Type "/toggle-bit 3"
49+
Enter
50+
Sleep 2s
51+
52+
# CAPTION: Complement flips every bit within the 4-bit width — value becomes 12
53+
Type "/not"
54+
Enter
55+
Sleep 2s
56+
57+
# CAPTION: Shift left 1 bit — the MSB is 1, so overflow is reported
58+
Type "/shl 1"
59+
Enter
60+
Sleep 2s
61+
62+
# CAPTION: Rotate right 2 — bits wrap around, no bits are lost
63+
Type "/ror 2"
64+
Enter
65+
Sleep 2s
66+
67+
# ════════════════════════════════════════════════════════════════════════════
68+
# 8-BIT section
69+
# ════════════════════════════════════════════════════════════════════════════
70+
71+
# CAPTION: Switch to 8-bit — the classic byte representation
72+
Type "/size 8"
73+
Enter
74+
Sleep 2s
75+
76+
# CAPTION: Set 85 — alternating bits 01010101 in binary
77+
Type "/set 85"
78+
Enter
79+
Sleep 2s
80+
81+
# CAPTION: Display just the binary representation
82+
Type "/bin"
83+
Enter
84+
Sleep 2s
85+
86+
# CAPTION: Display the octal representation
87+
Type "/oct"
88+
Enter
89+
Sleep 2s
90+
91+
# CAPTION: Display the hexadecimal representation
92+
Type "/hex"
93+
Enter
94+
Sleep 2s
95+
96+
# CAPTION: Set bit 7 (the MSB) to 1 — value jumps from 85 to 213
3797
Type "/set-bit 7"
3898
Enter
3999
Sleep 2s
@@ -43,84 +103,166 @@ Type "/reset-bit 0"
43103
Enter
44104
Sleep 2s
45105

46-
# CAPTION: Toggle bit 4 to flip it from 1 to 0
47-
Type "/toggle-bit 4"
106+
# CAPTION: Shift left 1 — the MSB was 1, so one bit is lost to overflow
107+
Type "/shl 1"
48108
Enter
49109
Sleep 2s
50110

51-
# ── Octal group manipulation ─────────────────────────────────────────────────
52-
# CAPTION: Clear the value back to zero before exploring octal groups
53-
Type "/clear"
111+
# CAPTION: Logical shift right 3 — zeros fill in from the left
112+
Type "/shr 3"
54113
Enter
55-
Sleep 1s
114+
Sleep 2s
56115

57-
# CAPTION: Set the rightmost octal group (bits 0–2) to 5
58-
Type "/set-octal 0 5"
116+
# CAPTION: Rotate left 4 — the high nibble and low nibble swap
117+
Type "/rol 4"
59118
Enter
60119
Sleep 2s
61120

62-
# CAPTION: Set the middle octal group (bits 3–5) to 2
63-
Type "/set-octal 1 2"
121+
# CAPTION: Rotate right 4 — restores the previous arrangement
122+
Type "/ror 4"
64123
Enter
65124
Sleep 2s
66125

67-
# CAPTION: Set the leftmost octal group (bits 6–7) to 1 — now octal 125
68-
Type "/set-octal 2 1"
126+
# CAPTION: Set the rightmost octal group (bits 0–2) to 7
127+
Type "/set-octal 0 7"
69128
Enter
70129
Sleep 2s
71130

72-
# ── Hex group manipulation ───────────────────────────────────────────────────
73-
# CAPTION: Clear and demonstrate hex group manipulation
74-
Type "/clear"
131+
# CAPTION: Set the middle octal group (bits 3–5) to 5
132+
Type "/set-octal 1 5"
75133
Enter
76-
Sleep 1s
134+
Sleep 2s
77135

78-
# CAPTION: Set the low nibble (bits 0–3) to hex A
79-
Type "/set-hex 0 10"
136+
# CAPTION: Set the high hex nibble (bits 4–7) to hex A
137+
Type "/set-hex 1 10"
80138
Enter
81139
Sleep 2s
82140

83-
# CAPTION: Set the high nibble (bits 4–7) to hex B — now 0xBA
84-
Type "/set-hex 1 11"
141+
# CAPTION: AND with 0b11110000 — clears the low nibble, keeps the high
142+
Type "/and 0b11110000"
85143
Enter
86144
Sleep 2s
87145

88-
# ── Random values ────────────────────────────────────────────────────────────
89-
# CAPTION: Generate a random 8-bit value
90-
Type "/random"
146+
# CAPTION: OR with 0x0F — fills the low nibble with all 1s
147+
Type "/or 0x0F"
91148
Enter
92149
Sleep 2s
93150

94-
# CAPTION: Generate another random value — full 0–255 range
151+
# CAPTION: XOR with 0xAA — flips every other bit
152+
Type "/xor 0xAA"
153+
Enter
154+
Sleep 2s
155+
156+
# CAPTION: Generate a random 8-bit value across the full 0–255 range
95157
Type "/random"
96158
Enter
97159
Sleep 2s
98160

99-
# ── Undo / redo ──────────────────────────────────────────────────────────────
100-
# CAPTION: Undo to restore the previous random value
161+
# CAPTION: Save this session to disk for reloading later
162+
Type "/save /tmp/uint-demo.json"
163+
Enter
164+
Sleep 2s
165+
166+
# CAPTION: Undo the random — restores the previous value
101167
Type "/undo"
102168
Enter
103169
Sleep 2s
104170

105-
# CAPTION: Redo to reapply the undone change
171+
# CAPTION: Redo to reapply the random value
106172
Type "/redo"
107173
Enter
108174
Sleep 2s
109175

110-
# ── Switch to 16-bit representation ─────────────────────────────────────────
111-
# CAPTION: Switch to a 16-bit integer — value resets to 0
176+
# ════════════════════════════════════════════════════════════════════════════
177+
# 16-BIT section
178+
# ════════════════════════════════════════════════════════════════════════════
179+
180+
# CAPTION: Switch to 16-bit — hex and octal groups multiply; notice the coloured boundary bars
112181
Type "/size 16"
113182
Enter
114183
Sleep 2s
115184

116-
# CAPTION: Set a value that shows the wider bit and hex groupings clearly
117-
Type "/set 43981"
185+
# CAPTION: Set 0xABCD — a value that shows all hex digits clearly
186+
Type "/set 0xABCD"
118187
Enter
119188
Sleep 2s
120189

121-
# ── Save and quit ────────────────────────────────────────────────────────────
122-
# CAPTION: Save the current session to disk
123-
Type "/save /tmp/uint-demo.json"
190+
# CAPTION: Display the decimal equivalent
191+
Type "/dec"
192+
Enter
193+
Sleep 2s
194+
195+
# CAPTION: Shift left 4 bits — the top hex digit overflows
196+
Type "/shl 4"
197+
Enter
198+
Sleep 2s
199+
200+
# CAPTION: Shift right 4 to restore the lower three hex digits
201+
Type "/shr 4"
202+
Enter
203+
Sleep 2s
204+
205+
# CAPTION: Rotate left 8 — swaps the high byte and low byte
206+
Type "/rol 8"
207+
Enter
208+
Sleep 2s
209+
210+
# CAPTION: AND with 0xFF00 — masks out the low byte, isolates the high byte
211+
Type "/and 0xFF00"
212+
Enter
213+
Sleep 2s
214+
215+
# CAPTION: OR with 0x00FF — fills the low byte back with all 1s
216+
Type "/or 0x00FF"
217+
Enter
218+
Sleep 2s
219+
220+
# CAPTION: Complement the entire 16-bit value
221+
Type "/not"
222+
Enter
223+
Sleep 2s
224+
225+
# CAPTION: Generate a random 16-bit value
226+
Type "/random"
227+
Enter
228+
Sleep 2s
229+
230+
# ════════════════════════════════════════════════════════════════════════════
231+
# 32-BIT section
232+
# ════════════════════════════════════════════════════════════════════════════
233+
234+
# CAPTION: Switch to 32-bit — the magenta bars now mark every 12-bit LCM boundary
235+
Type "/size 32"
236+
Enter
237+
Sleep 2s
238+
239+
# CAPTION: Set a well-known 32-bit pattern — 0xDEADBEEF
240+
Type "/set 0xDEADBEEF"
241+
Enter
242+
Sleep 2s
243+
244+
# CAPTION: Shift right 16 — isolates the upper word in the lower 16 bits
245+
Type "/shr 16"
246+
Enter
247+
Sleep 2s
248+
249+
# CAPTION: Rotate left 16 — swaps the upper and lower 16-bit halves
250+
Type "/rol 16"
251+
Enter
252+
Sleep 2s
253+
254+
# CAPTION: XOR with 0xFFFFFFFF — equivalent to a full complement
255+
Type "/xor 0xFFFFFFFF"
256+
Enter
257+
Sleep 2s
258+
259+
# CAPTION: Generate a random 32-bit value
260+
Type "/random"
261+
Enter
262+
Sleep 2s
263+
264+
# CAPTION: Reload the 8-bit session saved earlier — size and value both restore
265+
Type "/load /tmp/uint-demo.json"
124266
Enter
125267
Sleep 2s
126268

0 commit comments

Comments
 (0)