Feature Tour, Part 3: Interactive Components in MDX
A demonstration of embedding a small interactive React component in an MDX article, using a byte-sized two's complement explorer.
Published 1 min readCategory: Systems Programming
On this page
MDX articles can import components and use them alongside Markdown. Static components, like the callout above, render to plain HTML at build time. Interactive components are hydrated as small islands, and only on the pages that use them. This is the only article that loads the script for the explorer below.
Two’s complement in one byte
A byte has eight bits. Read as an unsigned integer, the bits have weights through , giving values from 0 to 255. In two’s complement, the most significant bit instead has weight , giving values from to :
Try flipping bits. Setting only bit 7 gives 128 as an unsigned value but as a signed one. Setting every bit gives 255 and .
Bit explorer (interactive demo)
Each button is one bit, most significant first. Press a bit to flip it.
- unsigned
- 42
- signed
- 42
- hex
- 0x2A
The same idea in C
Converting between the two interpretations does not change any bits; it only changes how they are read:
#include <stdint.h>#include <stdio.h>
int main(void){ uint8_t raw = 0xFF; int8_t as_signed = (int8_t)raw; /* implementation-defined before C23; -1 in practice */ printf("%u %d\n", raw, as_signed); return 0;}