FIND YOUR NEXT FEW LINES

Results for “Binary formats & structured parsing”

Small, practical examples. Search by task or narrow things down below.

155 snippets foundClear filters
CFiles

Write and read binary bytes

Round-trip a byte buffer through a C binary file.

C✓ Tested
JavaEncoding & structured values

Inspect components of a URI

Java: Use URI parsing instead of splitting a URL at punctuation manually.

Java✓ Tested
PythonStructured data & serialization

Pack and unpack a network-order integer

Python: Use an explicit byte order so the binary format is independent of the host architecture.

Python✓ Tested
JavaEncoding & structured values

Read a big-endian integer from bytes

Java: Set a byte order explicitly when handling a binary protocol.

Java✓ Tested
Arduino / CBinary values & packets

Assemble a big-endian 16-bit value

Arduino / C: Cast to an unsigned 16-bit type before shifting the high byte.

Arduino / C✓ Tested
Arduino / CBinary values & packets

Assign a bit from a Boolean state

Arduino / C: bitWrite accepts a bit position and a zero or nonzero value.

Arduino / C✓ Tested
Arduino / CBinary values & packets

Calculate a CRC-8 over a byte sequence

Arduino / C: This implementation uses polynomial 0x07, initial zero, and no reflection.

Arduino / C✓ Tested
CNumeric parsing & arithmetic

Calculate a page count without an overflowing addition

C: Divide first and add one only when a nonzero remainder remains.

C✓ Tested
JavaEncoding & structured values

Calculate a SHA-256 content digest

Java: Hash UTF-8 bytes and format the result as lowercase hexadecimal.

Java✓ Tested
Arduino / CBinary values & packets

Calculate a simple packet XOR checksum

Arduino / C: XOR all payload bytes to produce a basic error-detection byte.

Arduino / C✓ Tested
C++Numeric parsing & calculations

Calculate a two-dimensional vector length

C++: hypot avoids unnecessary intermediate overflow in the sum of squares.

C++✓ Tested
C++Text validation & parsing

Check a literal prefix in C++17

C++: Use string compare because starts_with was introduced after C++17.

C++✓ Tested