Integers

This integer representation is based on Humbers as described in Literary Machines by Ted Nelson. The major differences are:

An Integer consists of at least one eight bit byte.

Bit 7 (the high order bit) of the first byte is the EXTENDED bit. If it is zero, the Integer is a small integer, and is encoded entirely in the first byte. In this case, bits [6..0] are the VALUE field, with bit 6 being the sign bit. The integers [-64..63] can be encoded in this way.

If EXTENDED is one, the LONG bit determines how to decode the integer.

Bit 6 of the first byte is the LONG bit. If it is zero, bits [5..0] are the LENGTH field, and encode the length of the VALUE field of the Integer in bytes. Four of these length values are reserved for non-numeric values. These values include signaling and non-signaling versions of NaN (Not a Number) and positive and negative Infinity. The NaN and Infinity values are all encoded in one byte. See below for the encodings of these values. The integers [-(2471)..(2471-1)] can be encoded in the up to 472 bits available when LONG is zero.

If the LONG bit is one, bits [5..0] are the LONGLENGTH field, and encode the number of bytes in the LENGTH field, which follows. A value of zero in either the LENGTH or LONGLENGTH fields is meaningless, and any such Integer is considered undefined. The LENGTH field can be up to 63 bytes long, or 504 bits. Thus, the VALUE field can be up to 2504-1 bytes, or 2507-8 bits long. The integers [-(22507-9)..(22507-9-1)] can be encoded when LONG is one. This should suffice, at least for the near future.

The LENGTH and LONGLENGTH fields are not signed.

The VALUE field, and the LENGTH field for a LONG Integer, are encoded with the most significant byte first. Each subsequent byte is less significant than its predecessor. Leading zero bytes are explicitly allowed in either or both fields, and may be useful if an Integer must be filled in at a later time without changing the overall length of the Integer. This can obviously only be done if an upper bound for the length of the Integer can be set when it is first written.

EXTENDED=0

0sxx xxxx           Small seven bit signed integer [-64..+63]

EXTENDED=1  LONG=0

1000 0000           undefined

1011 1100	    non-signaling NaN
1011 1101	    signaling NaN
1011 1110	    +Infinity
1011 1111	    -Infinity

// Note:  Do I need signaling vs non-signaling Infinities?

10LL LLLL L bytes of VALUE
                    0 < L <= 59
                    Large integer (L*8 bits, including sign bit)

EXTENDED=1  LONG=1

1100 0000           undefined
1100 0001 0000 0000 undefined
11LL LLLL L bytes of LENGTH, LENGTH bytes of VALUE
                    0 < L <= 63

Examples (all numbers are in hex):

Value                Representation
0                    00
0                    81 00
0                    82 00 00
0		     84 00 00 00 00
0                    C1 01 00
3F                   3F
40                   81 40
7F                   81 7F
80                   82 00 80
100                  82 01 00
-1                   7F
-2                   7E
-3F                  41
-40                  40
-41                  81 BF

Notes: The LONGLENGTH field will almost certainly be used (it's not just wild extravagance). Without the LONGLENGTH field, the largest integer that could be represented would be 2983. Integers larger than this are routinely in use today as cryptographic keys.