F2 Data representation and bit operations

Needs: Supporter

Hex, binary, BCD, ASCII and EBCDIC, XOR and bit numbering: the encodings behind most payment bugs.

This is a supporter feature. Create a free account, then try every supporter feature free for 7 days.

Sign in Create a free account See plans

What this module covers

Track F · Foundations

You will be able to

  • Convert between hex, binary, decimal, packed and unpacked BCD, ASCII and EBCDIC
  • XOR two values
  • Read bit numbers the ISO 8583 and EMV way (bit 1 is the leftmost)

The lesson

  1. Why it matters
  2. The concept
  3. Step by step
  4. In the real world
  5. Common mistakes
  6. What to test

In the module

  • The lesson, with diagrams, common mistakes and what to test
  • A worked example you can change: One value, many encodings
  • Practice: 5 kinds of generated exercise, each with a step-by-step solution
  • A quiz of 8 questions

Key terms

ASCII
The common 7-bit character set: digits are 30–39 hex, 'A' is 41. Many ISO 8583 implementations send numeric and text fields in ASCII.
Base64
A text encoding of binary data with 64 characters. Common in APIs and certificates (PEM), rare inside ISO 8583.
BCD (Binary-coded decimal, packed decimal)
Decimal digits stored one per nibble, two per byte: 1234 is stored as the bytes 12 34. ISO 8583 numeric fields are often BCD on binary hosts.
Big-endian
Most significant byte first. Length headers and binary counters in payment messages are usually big-endian.
EBCDIC
The IBM mainframe character set. Digits are F0–F9 and letters are in other ranges than ASCII, so EBCDIC hosts need conversion at the switch.
Hexadecimal (Hex)
Base 16 written with 0–9 and A–F. Each hex digit is 4 bits, so one byte is two hex digits; keys, blocks and MACs are usually written in hex.
Justification
Where a value sits in a fixed-length field: numbers are usually right-justified with leading zeros, text left-justified with trailing spaces.
Nibble
Half a byte: 4 bits, one hex digit.
XOR (Exclusive or)
The bit operation that gives 1 when the two bits differ. It is its own inverse, which is why it is used to combine key components, build PIN blocks and apply key variants.

Tools for this module: Code ConverterXOR / BitwiseBit Shift

Read the opening of the lesson →

The lesson, worked example, practice and quiz open with a supporter pass, which you can try free for 7 days.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.