Skip to content
UniKit

Hex protocol frame codec

Parse private protocol frames with your own template: uint/int 8–64, IEEE 754 float32/64, ascii, bcd, hex, bit fields and length-linked variable fields, with CRC16-Modbus, CRC16-CCITT-FALSE, sum8 and xor8 checksums; every field reports its offset and raw bytes, and edited values re-encode back to hex.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Field template

One field per line: name type [length] [options]; # or // starts a comment.

Parsed fields

Each field shows its offset, length, raw bytes and value; checksum fields also show expected vs actual.

Enter frame data to see the parsed fields

Re-encode

Editing a field re-encodes the frame; length and checksum fields are recalculated.

Encoded frame

Checksums: CRC16-Modbus (reflected 0xA001, init 0xFFFF), CRC16-CCITT-FALSE (0x1021, init 0xFFFF), sum8 and xor8; the stored value follows the field byte order.

What this tool does

  • You have a protocol document and a hex capture and want to know what each byte is: write the field table as a template and the parser reports offset, length, raw bytes and value for every field.
  • Debug a private protocol: change a field value and the tool re-encodes the whole frame, recalculating length and checksum fields for you.
  • Check a checksum: when it fails you see the expected value, the actual value and which fields the checksum covers.
  • Handle bit fields and variable-length frames: split run/dir/speed/mode out of one byte and let the payload length follow the length field.

Example

Input

48 4B 02 DB 00 04 01 02 00 00 CC 41 DE AD BE EF 4E 9A

Output

magic=HK · version=2 · flags=0xDB (run=1 dir=1 speed=3 mode=3) · len=4 · seq=258 · temp=25.5 · payload=DE AD BE EF · crc=0x9A4E (checksum OK)

Template: magic ascii 2 / version u8 / flags bits 8 run:1 dir:1 speed:3 mode:3 / len len16 of=payload endian=be / seq u16 endian=be / temp f32 endian=le / payload hex of=len / crc checksum crc16modbus over=0..-2 endian=le. temp is float32 little-endian 25.5, len carries the payload byte count and crc is CRC16-Modbus over the first 16 bytes written little-endian.

Frequently asked questions

What is the template syntax?

One field per line: `name type [length] [options]`, with `#` or `//` starting a comment. Types: u8/u16/u32/u64, i8/i16/i32/i64, f32/f64, ascii, bcd, hex, bits, len8, len16, checksum. For ascii the length is characters, for bcd/hex it is bytes and for bits it is the total bit count (a multiple of 8). Options: endian=le|be, of=field, algo=checksum, over=from..to, fill=0x20. Bit fields are written inline after the length: `run:1 dir:1 speed:3 mode:3`.

Which field types and checksums are supported?

Signed and unsigned integers of 8/16/32/64 bits, IEEE 754 float32/float64, fixed-length ascii, BCD, raw hex, bit fields, plus len8/len16 length fields. Checksums: CRC16-Modbus, CRC16-CCITT-FALSE, sum8 and xor8. The CRC parameters are the published ones — Modbus uses the reflected polynomial 0xA001 with init 0xFFFF, CCITT-FALSE uses 0x1021 with init 0xFFFF — and the unit tests assert the standard "123456789" vectors (0x4B37 and 0x29B1).

How do variable-length fields work?

Both directions: `payload hex of=len` means the payload byte count comes from the len field, while `len len16 of=payload` means len stores the payload byte length. On parse the payload is sliced by the length field; on encode the length field is recalculated from the target field and any value you typed is ignored. The length field of a hex field must be declared before it (otherwise template-order); the target of a len field may come later.

How are bit fields split?

`flags bits 8 run:1 dir:1 speed:3 mode:3`: the sub-field widths must add up to the total, split from the most significant bit down in the usual big-endian register order (in the example 0xDB = 11011011 gives run=1, dir=1, speed=011=3, mode=011=3). On encode you can supply the whole value (decimal or 0x hex) or individual sub-fields such as `flags.run=1`.

What happens when the checksum fails?

Parsing continues: the checksum field reports the algorithm, the field range it covers and both the expected and the actual value (for example expected=0x9A4E, actual=0x004E), and the frame is marked as not OK. That way you can still read the other fields before deciding whether the frame or the algorithm/byte order is wrong — Modbus checksums are usually little-endian, CCITT big-endian.

Does it compress, decrypt or infer templates?

No. It is a pure bit-level parser driven by the template you write: no decompression, no decryption and no guessing of field layouts; bytes the template does not cover are reported separately. Everything runs locally in the browser and frame data is never uploaded.

Keywords:hex frameprotocol parserCRC16 ModbusCRC16 CCITTbinary template

Related tools