Mainframe data is bytes—not always readable characters. Packed decimal stores two digits per byte except the sign nybble. Binary flags set individual bits in a halfword. EBCDIC digits look like X'F1F2F3' for one-two-three in display form, not 123 as you type on a keyboard. Easytrieve hexadecimal literals let you specify exact byte patterns with X'...' syntax. Hex masks in AND, OR, and XOR assignments flip bits without decimal math. MASK HEX on DEFINE formats DISPLAY output as hex strings for debugging. Beginners who only use character DISPLAY on packed fields see gibberish or misleading digits—hex view reveals truth. This page teaches literal syntax, nybble layout, common EBCDIC and packed patterns, mask widths, and VALUE initialization with hex constants.
Prefix X, open single quote, hex digits 0-9 and A-F, close quote. X'00' is one byte of binary zeros. X'0000' is two bytes. Digits must be even count—each pair is one byte. No decimal point, no spaces inside quotes. Use hex literals anywhere literals are accepted: VALUE on DEFINE, assignment right-hand side, AND OR XOR mask operand.
123456DEFINE FLAGS W 2 B VALUE X'0000' DEFINE SEED W 2 P VALUE X'123F' DEFINE SPACES W 2 A VALUE X'4040' FLAGS = FLAGS OR X'0001' SEED = SEED AND X'FF00'
One byte equals eight bits, written as two hex digits. High nybble is left digit, low nybble is right digit. Packed decimal squeezes two decimal digits into one byte—the last nybble is sign. Binary X'80' sets high bit of one byte—128 unsigned or negative in signed byte interpretation depending on context.
| Hex literal | Bytes | Typical meaning |
|---|---|---|
| X'F0' | 1 | EBCDIC digit 0 |
| X'40' | 1 | EBCDIC space |
| X'4040' | 2 | Two EBCDIC spaces |
| X'123F' | 2 | Packed decimal +123 |
| X'123D' | 2 | Packed decimal -123 |
| X'FFFE' | 2 | Bit mask clearing low bit |
Zoned decimal N field storing 123 in three bytes EBCDIC often looks like X'F1F2F3' in hex—one zone and digit per byte in classic display format. Packed P two-byte 123 is X'123F'—compact. Binary B two-byte value 255 is X'00FF' on big-endian layout depending on field definition. Comparing hex dumps across types prevents declaring wrong type on FILE lines.
Logical assignment: receive = send AND mask clears bits where mask bit is zero. OR sets bits where mask is one. XOR toggles. Mask width should match field byte length—two-byte field uses four hex digits inside X'....'. Applying X'FF' mask to four-byte field only affects low byte—high bytes unchanged unless mask includes leading FFFF.
123456DEFINE F1P W 2 P MASK HEX DEFINE F2P W 2 P VALUE X'123D' F1P = F2P AND X'FFFE' F1P = F2P OR X'000F' F1P = F2P XOR X'FFFF'
AND X'FFFE' clears bit zero of low byte. OR X'000F' sets low four bits. XOR X'FFFF' inverts all sixteen bits in two-byte field. Test each step with DISPLAY HEX before production flag updates on interface records.
VALUE X'123F' on DEFINE sets initial packed content at compile/load—not runtime file read. Useful for constant seeds, clearing flags to X'0000', or presetting test records in working storage. FILE fields do not use VALUE for file content—they read from dataset bytes. Distinguish initialization from assignment inside JOB logic.
DEFINE field MASK HEX formats numeric or character fields as hexadecimal on DISPLAY and some report contexts. Documentation notes display up to 50 bytes with HEX mask. Essential when teaching new developers packed layout—show X'123F' alongside edited decimal print from separate masked field.
Mainframe EBCDIC digit zero is X'F0'; ASCII is X'30'. Literals and file data follow installation charset. Porting hex constants from PC documentation without conversion produces wrong character comparisons. IF STATUS EQ X'40' tests one EBCDIC space byte when STATUS is A 1—verify literal matches encoding.
EVEN on P fields forces even digit count with leading zero nybble—two-byte even packed two digits appears X'012F' for positive twelve. Hex dump inspection confirms EVEN attribute applied correctly when copybook ambiguous.
Hex is a secret code for bytes. Instead of writing every bit as on-off, we use two symbols 0-9 and A-F for each chunk of eight switches. X'FF' means all eight switches in one chunk are on. Masks are stencils—you lay the stencil on your byte and paint only the spots that should change. That is how programs flip one flag without breaking the rest of the number.
1. Hexadecimal literals in Easytrieve are prefixed with:
2. Literal X'4040' contains how many bytes?
3. Packed decimal 123 positive often appears as hex:
4. MASK HEX on DEFINE is used to:
5. EBCDIC digit zero is hex: