Results for “Binary formats & structured parsing”
Small, practical examples. Search by task or narrow things down below.
Convert ASCII text to lowercase safely
C: Cast to unsigned char before calling ctype functions on a possibly signed char.
C✓ Tested
Decode a 16-bit big-endian integer
C: Promote bytes to an unsigned integer type before combining shifted values.
C✓ Tested
Decode a validated pair of hexadecimal digits
C: Convert each nibble and reject a nonhexadecimal character before combining them.
C✓ Tested
Encode a byte buffer as hexadecimal
C: Format each byte as an unsigned two-digit hexadecimal value.
C✓ Tested
Format a known timestamp in UTC
C: gmtime converts to UTC calendar fields and strftime formats them.
C✓ Tested
Format a nonnegative integer amount as whole and fractional units
C: Keep the calculation in integer minor units and use two digits for the remainder.
C✓ Tested
Parse a bounded simple record with sscanf
C: A width limit protects the destination buffer and the consumed count detects trailing junk.
C✓ Tested
Quote a CSV field and double embedded quotes
C: A quoted CSV field represents a quote character by repeating it.
C✓ Tested
Serialize a 16-bit integer in big-endian order
C: Explicit shifts make a byte format independent of the CPU’s native byte order.
C✓ Tested
Validate a simple C-style ASCII identifier
C: Check the first character separately from subsequent characters and reject empty input.
C✓ Tested
Read a big-endian binary integer
C#: Use BinaryPrimitives when the protocol byte order differs from or must not depend on the host.
C#✓ Tested
Write and read typed binary fields
Java: Data streams use a matching write/read order and fixed encodings for Java primitive values.
Java✓ Tested