Provides a few functions for manipulating the bits in single cells. Note that this is distinct from the y_bit library.
(c) 2022 YSI contibutors, licensed under MPL 1.1
-538976289
-2139062144
-16843009
Cell_Abs(GLOBAL_TAG_TYPES:x, m)
Cell_Abs(number, tag)
Name | Info |
---|---|
number |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the absolute value of. |
tag |
The tag of the number, in case its Float . |
The absolute value of a number.
Get the absolute value of a number. Floats just remove MSB. For ints, multiply the whole number by the MSB shifted OR 1 (1 or -1).
1 cells
Cell_CompressRight(GLOBAL_TAG_TYPES:x, m);
Cell_CompressRight(x, m)
Name | Info |
---|---|
x |
{_,Bit,Text,Group,File,Float,Text3D} The number to compress. |
m |
The mask for which bits to compress. |
Selected bits from "x", shifted to be LSBs.
Doesn't require precomputation.
12 cells
Cell_CompressRightPrecomputed(GLOBAL_TAG_TYPES:x, m, masks[5]);
Cell_CompressRightPrecomputed(x, m, masks[])
Name | Info |
---|---|
x |
{_,Bit,Text,Group,File,Float,Text3D} The number to compress. |
m |
The mask for which bits to compress. |
masks |
[5] Precomputed constants for the compression. |
Selected bits from "x", shifted to be LSBs.
Very briefly, do "x & m", to select certain bits, then shift those bits by various amounts so that they are consecutive: x = 0b110011 m = 0b011010 x & m = 0b010010 From here, because the mask was three bits we know we want just those three bits in the LSBs, so the answer becomes: 0b000101 Just read this question, it has a diagram: http://stackoverflow.com/questions/28282869/shift-masked-bits-to-the-lsb
2 cells
Cell_CountBits(number);
Cell_CountBits(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the number of 1s in. |
The number of 1s (set bits) in the input.
- Example: 0 Returns: 0 2) Example: 1 Returns: 1 3) Example: 0x01010101 Returns: 4 I rewrote this in assembly just to see if I could pretty much. I also rewrote the lookup version in assembly. In theory it should be faster, but the marshalling of data was a little awkward.
1 cells
Cell_CountBlanks(number);
Cell_CountBlanks(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the number of 0s in. |
The number of 0s (unset bits) in the input.
Like Cell_CountBits, but for 0s not 1s.
1 cells
Cell_ExpandLeft(GLOBAL_TAG_TYPES:x, m)
Cell_ExpandLeft(x, m)
Name | Info |
---|---|
x |
{_,Bit,Text,Group,File,Float,Text3D} The number to expand. |
m |
The mask for which bits to expand to. |
LSBs from "x", shifted to selected bit positions.
Doesn't require precomputation.
12 cells
Cell_ExpandLeftPrecomputed(GLOBAL_TAG_TYPES:x, m, masks[5])
Cell_ExpandLeftPrecomputed(x, m, masks[])
Name | Info |
---|---|
x |
{_,Bit,Text,Group,File,Float,Text3D} The number to expand. |
m |
The mask for which bits to expand to. |
masks |
[5] Precomputed constants for the expansion. |
LSBs from "x", shifted to selected bit positions.
The reverse of "Cell_CompressRightPrecomputed". Doesn't return exactly the original number before a compression, just the original number ANDed with the mask "m".
2 cells
Cell_GetLowestBit(number);
Cell_GetLowestBit(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest set bit of. |
The integer position of the lowest set bit.
- Example: 0b00000000000000000000000000000001 Returns: 0 2) Example: 0b00000000000000000000000000001000 Returns: 3 3) Example: 0b00010001100011000011100010001000 Returns: 3 NOTE: This function returns "0" for both numbers with the "1" bit set AND the number "0", which has NO bits set. Check that the number is valid before passing it to this function. See: http://supertech.csail.mit.edu/papers/debruijn.pdf
1 cells
Cell_GetLowestBitEx(number);
Cell_GetLowestBitEx(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest set bit of PLUS ONE. |
The integer position of the lowest set bit PLUS ONE.
This function is identical to "Cell_GetLowestBit", but gives different results for 0 and non-zero numbers. The examples below all have a result one higher than the "Cell_GetLowestBit" function. 1) Example: 0b00000000000000000000000000000001 Returns: 1 2) Example: 0b00000000000000000000000000001000 Returns: 4 3) Example: 0b00010001100011000011100010001000 Returns: 4 4) Example: 0 Returns: 0 See: http://supertech.csail.mit.edu/papers/debruijn.pdf
1 cells
Cell_GetLowestBlank(number);
Cell_GetLowestBlank(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest unset bit of. |
The integer position of the lowest unset bit.
Like Cell_GetLowestBit, but for 0s not 1s.
1 cells
Cell_GetLowestBlankEx(number);
Cell_GetLowestBlankEx(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest unset bit of PLUS ONE. |
The integer position of the lowest unset bit PLUS ONE.
Like Cell_GetLowestBitEx, but for 0s not 1s.
1 cells
Cell_GetLowestComponent(number);
Cell_GetLowestComponent(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest 1 in. |
The lowest set bit.
Similar to Cell_GetLowestBit, but returns the bit, not the position of the bit. 1) Example: 0b00000000000000000000000000000001 Returns: 0b00000000000000000000000000000001 2) Example: 0b00000000000000000000000000001000 Returns: 0b00000000000000000000000000001000 3) Example: 0b00010001100011000011100010001000 Returns: 0b00000000000000000000000000001000 4) Example: 0b00000000000000000000000000000000 Returns: 0b00000000000000000000000000000000
1 cells
Cell_GetLowestEmpty(number);
Cell_GetLowestEmpty(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest 0 in. |
The lowest unset bit.
Like Cell_GetLowestComponent, but for 0s not 1s.
1 cells
Cell_HasSpaceByte(number);
Cell_HasSpaceByte(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest space in. |
The lowest space byte.
Check if any of the 4 bytes are a space: https://jameshfisher.com/2017/01/24/bitwise-check-for-zero-byte/
1 cells
Cell_HasZeroByte(number);
Cell_HasZeroByte(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to get the lowest 0 in. |
The lowest null byte.
Check if any of the 4 bytes are zero: https://jameshfisher.com/2017/01/24/bitwise-check-for-zero-byte/
1 cells
Cell_PrecomputeMaskPermutation(m)
Cell_PrecomputeMaskPermutation(m)
Name | Info |
---|---|
m |
The mask. |
Five precomputed constants to help expand or contract this mask.
The full maths for generalised expansion and contraction is quite complex; however, much of the inner loop relies only on the mask and not on the value being manipulated. Given this we can do a lot of work in advance, say outside a loop, to avoid repeated calculations.
10 cells
Cell_ReverseBits(number);
Cell_ReverseBits(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to manipulate. |
All the bits in the input reversed.
- Example: 0b11110000000000000000000000000000 Becomes: 0b00000000000000000000000000001111 2) Example: 0b10110011100011110000111110000010 Becomes: 0b01000001111100001111000111001101 3) Example: 0b01010101010101010101010101010101 Becomes: 0b10101010101010101010101010101010
1 cells
Cell_ReverseBytes(number);
Cell_ReverseBytes(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to manipulate. |
All the bytes in the input reversed.
- Example: 0x12345678 Becomes: 0x78563412 2) Example: 0x01020304 Becomes: 0x04030201 3) Example: 0xFF00FF00 Becomes: 0x00FF00FF
native
Cell_ReverseNibbles(number);
Cell_ReverseNibbles(data)
Name | Info |
---|---|
data |
{_,Bit,Text,Group,File,Float,Text3D} The number to manipulate. |
All the nibbles (4-bit chunks) in the input reversed.
- Example: 0x12345678 Becomes: 0x87654321 2) Example: 0x010F0703 Becomes: 0x3070F010 3) Example: 0xF0F0F0F0 Becomes: 0x0F0F0F0F
1 cells