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 8
set result: fit.and(16, 2) # result is 0
set result: fit.and(15, 3) # result is 3
set 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 12288
set result: fit.left(16, 2) # result is 64
set result: fit.left(15, 53) # result is -9007199254740992

fit.mask(number)

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.mask(1)     #  1                            (0x00000000000001)
fit.mask(3)     #  7                            (0x00000000000007)
fit.mask(8)     #  255                          (0x000000000000FF)
fit.mask(16)    #  65_535                       (0x0000000000FFFF)
fit.mask(32)    #  4_294_967_295                (0x000000FFFFFFFF)
fit.mask(55)    #  36_028_797_018_963_967       (0x7FFFFFFFFFFFFF)
fit.mask(56)    #  -1                           (0xFFFFFFFFFFFFFF)
fit.mask(57)    #  null
fit.mask(-1)    #  -2                           (0xFFFFFFFFFFFFFE)
fit.mask(-3)    #  -8                           (0xFFFFFFFFFFFFF8)
fit.mask(-8)    #  -256                         (0xFFFFFFFFFFFF00)
fit.mask(-16)   #  -65_536                      (0xFFFFFFFFFF0000)
fit.mask(-32)   #  -4_294_967_296               (0xFFFFFF00000000)
fit.mask(-55)   #  -36_028_797_018_963_968      (0x80000000000000)
fit.mask(-56)   #  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 14
set result: fit.or(16, 2) # result is 18
set result: fit.or(15, 3) # result is 15
set 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 0
set result: fit.right(19, 2) # result is 4
set 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 6
set result: fit.xor(16, 2) # result is 18
set result: fit.xor(15, 3) # result is 12
set result: fit.xor(13, 3) # result is 14 set result: fit.xor(13.01, 3) # result is null

fit.zeros(fit)

Leading zeros. Count the number of leading zeros.

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