alphanumeric provides printf-like numeric formatting and scanf-like numeric parsing without any libc dependency. It is the bridge between the UART byte stream and the typed values that PRINT and READ expose to user processes.
All conversion functions use fixed-size stack buffers of 16 bytes. No heap allocation is performed.
Functions
uart_putnum
\n). Uses a 16-byte stack buffer and builds the digit string in reverse before sending. If num is 0, outputs "0\n" immediately.
uart_itoa
buffer. The buffer must be at least 16 bytes. The output is null-terminated.
Handles negative numbers by prepending '-'. Builds digits in reverse internally, then reverses the buffer in place.
| Input | Output in buffer |
|---|---|
0 | "0" |
42 | "42" |
-7 | "-7" |
uart_ftoa
float to its decimal string representation and stores the result in buffer. The buffer must be at least 16 bytes. The output is null-terminated and includes a decimal point.
The implementation separates the integer and fractional parts. The fractional part is expanded by repeated multiplication by 10 until it has no remaining fractional component (i.e., the loop while (decpart - (float)((int)decpart)) terminates when the decimal is exact in floating point). This means precision depends on whether the fractional value is exactly representable.
The precision of
uart_ftoa is limited by floating-point representation. Values whose fractional parts cannot be expressed exactly in IEEE 754 single precision may produce unexpected digit sequences.uart_atoi
int value. Handles an optional leading '-' for negative numbers. Stops at the first non-digit character.
uart_atof
float value. Handles an optional leading '-' and a single '.' as the decimal separator. Stops at the first character that is neither a digit nor a period.
How PRINT uses these functions
PRINT in stdio.c calls uart_itoa and uart_ftoa to convert numeric arguments into stack-allocated strings, then passes those strings to uart_puts:
READ uses uart_atoi and uart_atof to parse the 16-character UART input buffer back into typed values: