• 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] YSI Daily Tips
#5
2021-04-17: y_cell

This is a library for fast bit-manipulation of cells:

Quote:
Cell_ReverseBits(cell);

Reverse all the bits in a cell:

Example: 0b11110000000000000000000000000000 Becomes: 0b00000000000000000000000000001111

Example: 0b10110011100011110000111110000010 Becomes: 0b01000001111100001111000111001101

Example: 0b01010101010101010101010101010101 Becomes: 0b10101010101010101010101010101010

Quote:
Cell_ReverseNibbles(cell);

Reverse all the nibbles in a cell:

Example: 0x12345678 Becomes: 0x87654321

Example: 0x010F0703 Becomes: 0x3070F010

Example: 0xF0F0F0F0 Becomes: 0x0F0F0F0F

Quote:
Cell_ReverseBytes(cell);

Reverse all the bytes in a cell:

Example: 0x12345678 Becomes: 0x78563412

Example: 0x01020304 Becomes: 0x04030201

Example: 0xFF00FF00 Becomes: 0x00FF00FF

Quote:
Cell_CountBits(cell);

Count all the 1s in a cell.

Example: 0 Returns: 0

Example: 1 Returns: 1

Example: 0x01010101 Returns: 4

Quote:
Cell_GetLowestBit(cell);

Returns a number between 0 and 31, representing the least significant set bit in a cell:

Example: 0b00000000000000000000000000000001 Returns: 0

Example: 0b00000000000000000000000000001000 Returns: 3

Example: 0b00010001100011000011100010001000 Returns: 3

WARNING: This function returns 0 if there are no bits set AND if the lowest bit is 1

Quote:
Cell_GetLowestComponent(cell);

Returns the lowest set bit in a cell:

Example: 0b00000000000000000000000000000001 Returns: 0b00000000000000000000000000000001

Example: 0b00000000000000000000000000001000 Returns: 0b00000000000000000000000000001000

Example: 0b00010001100011000011100010001000 Returns: 0b00000000000000000000000000001000


Messages In This Thread
YSI Daily Tips - by Y_Less - 2021-05-01, 05:25 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 05:40 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 06:59 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 06:59 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 06:59 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:06 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:06 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:06 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:07 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:07 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:08 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:08 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:08 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:09 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:09 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:09 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:09 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:10 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-01, 07:11 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-02, 07:44 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-03, 01:17 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-04, 08:08 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-05, 09:44 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-06, 02:46 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-07, 05:13 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-08, 08:08 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-09, 10:58 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-11, 08:55 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-11, 08:56 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-12, 09:41 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-13, 01:20 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-14, 08:20 PM
RE: YSI Daily Tips - by Y_Less - 2021-05-16, 07:41 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-16, 07:49 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-19, 11:25 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-19, 11:26 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-19, 11:27 AM
RE: YSI Daily Tips - by Y_Less - 2021-05-20, 10:05 AM
RE: YSI Daily Tips - by Y_Less - 2021-06-01, 09:26 AM
RE: YSI Daily Tips - by Y_Less - 2021-06-25, 08:06 PM
RE: YSI Daily Tips - by Y_Less - 2021-11-17, 09:12 PM
RE: YSI Daily Tips - by Y_Less - 2021-11-19, 12:21 AM
RE: YSI Daily Tips - by Y_Less - 2022-12-30, 09:56 PM
RE: YSI Daily Tips - by Y_Less - 2023-01-02, 01:25 AM
RE: YSI Daily Tips - by Y_Less - 2023-01-03, 12:17 AM

Forum Jump: