Misty Programming Language:

# Fit Functions

A felicitous number, or fit number for short, is a signed integer that fits in 56 bits. A fit number is an integer in the range `-36028797018963968` thru `36028797018963967`. The `fit` module provides functions that act upon fit integers.

`use fit`

If any of these functions is given an input that is not fit or not in range, the result is `null`.

#### fit.and(first, second)

And. The result is the bitwise `and` of the two fit integers.

Examples:

```set result: fit.and(12, 10)   # result is 8set result: fit.and(16, 2)    # result is 0set result: fit.and(15, 3)    # result is 3set result: fit.and(13, 3)    # result is 1
set result: fit.and("10", 3)  # result is null```

#### fit.left(first, second)

Left shift. It is similar to multiplying by a power of two. Bits that fall off of the left edge are lost.

Examples:

`set result: fit.left(12, 10)    # result is 12288set result: fit.left(16, 2)     # result is 64set result: fit.left(15, 53)    # result is -9007199254740992`

Mask. The `mask` function is used to generate bit fields that can be used with the other functions. If the number is `0`, then the result is zero. If the number is not an integer, or if it is greater than `56` or less than `-56`, then the result is `null`. If the number is positive, then a number containing that many `1` bits is generated. If the number is negative, then a number with that many (absolute) `0` bits is generated.

Examples:

```fit.mask(0)     #  0                            (0x00000000000000)

#### fit.not(fit)

Not. Flip every bit. Same as `fit.xor(fit, fit.mask(56))`.

#### fit.ones(fit)

Count the total number of `1` bits.

Examples:

```set result: fit.ones(-1)    # result is 56
set result: fit.ones(0)     # result is 0
set result: fit.ones(8)     # result is 1
set result: fit.ones(18)    # result is 2```

#### fit.or(first, second)

Or. The result is the bitwise `or` of the two values.

Examples:

`set result: fit.or(12, 10)   # result is 14set result: fit.or(16, 2)    # result is 18set result: fit.or(15, 3)    # result is 15set result: fit.or(13, 3)    # result is 15`

#### fit.reverse(first)

Reverse. Reverse the order of the bits.

Example:

`set result: fit.reverse(3141592653589793)    # result is 2334719610726733`

Right shift with zero fill.

Examples:

`set result: fit.`right`(12, 10)                   # result is 0set result: fit.`right`(19, 2)                    # result is 4set result: fit.`right`(-9007199254740992, 53)    # result is 7`

#### fit.right_signed(first, second)

Right shift with sign fill.

Examples:

`set result: fit.`right`(-2, 1)                   # result is -1`

#### fit.rotate(first, second)

Left shift with carry fill.

Examples:

```set result: fit.`rotate`(1, 1)                   # result is 2
```

#### fit.xor(first, second)

Exclusive or. The result is the bitwise exclusive-or of the two integers.

Examples:

```set result: fit.xor(12, 10)    # result is 6set result: fit.xor(16, 2)     # result is 18set result: fit.xor(15, 3)     # result is 12set result: fit.xor(13, 3)     # result is 14
set result: fit.xor(13.01, 3)  # result is null```

#### fit.zeros(fit)

Examples:

```set result: fit.zeros(-1)    # result is 0
set result: fit.zeros(0)     # result is 56
set result: fit.zeros(1)     # result is 55```