Binary
About
Stores numbers using the binary representation of the value.
Certain processors, like those from Intel, work in little-endian binary format. The majority of other platforms, like OS/390 and Solaris, work in big-endian binary format.
Negative values are stored as the two's complement representation of the value.
In COBOL on the PC:
- The 'COMP' data type is big-endian binary.
- The 'COMP-5' data type is little-endian binary.
On other platforms, like OS/390, the 'COMP' data type is big-endian binary and you can not represent little-endian binary values.
Big-endian means that the MSB (Most Significant Byte) of the number comes first.
Little-endian means that the LSB (Least Significant Byte) of the number comes first.
Limits
OS/390 COBOL programs can only handle a maximum of 18 digits (8 bytes).
Other
Also known as 'PCBS' and 'PCBU' on the PC.
Also known as 'MFBS' and 'MFBU' on OS/390.
Implied decimal places.
Use
Used on every platform.
Fastest data type for calculations on most platforms.
Big-endian examples
Unsigned
12345 is encoded in hex as 0033 0009 12345.67 is encoded in hex as 01D8 0267
Signed
+12345 is encoded in hex as 0033 0009 -12345.67 is encoded in hex as FE27 FD99
Little-endian examples
Unsigned
12345 is encoded in hex as 3300 9000 12345.67 is encoded in hex as 8D10 7620
Signed
+12345 is encoded in hex as 3300 9000 -12345.67 is encoded in hex as 72EF 99DF
Binary field sizes
No. of digits | No. of bytes (PC) | No. of bytes (OS/390) |
---|---|---|
1 | 1 | (half-word) 2 |
2 | 1 | 2 |
3 | 2 | 2 |
4 | 2 | 2 |
5 | 3 | (full-word) 4 |
6 | 3 | 4 |
7 | *4 | 4 |
8 | 4 | 4 |
9 | 4 | 4 |
10 | 5 | (double-word) 8 |
11 | 5 | 8 |
12 | **6 | 8 |
13 | 6 | 8 |
14 | 6 | 8 |
15 | 7 | 8 |
16 | 7 | 8 |
17 | 8 | 8 |
18 | 8 | 8 |
* This is 3 for unsigned binary fields
** This is 5 for unsigned binary fields