bnot( num )

Calculates the bitwise not of a number.

The number.

The bnot() function inverts all of the bits of a number.

Numbers in Pico-8 are stored using a 32-bit fixed point format, with 16 bits for the integer portion, 16 bits for the fractional portion, and a twos complement representation for negative and positive values. As a result, the bitwise-not of a number tends to be its negative. (bnot(0) is almost 0, but not quite.)

In cases where you're using bnot() you probably only care about specific bits and not the entire number. You can band() the result to mask out the bits you don't care about.

Examples Edit

--               0xb = 000...1011
--           not 0xb = 111...0100
--               0xf = 000...1111
-- (not 0xb) and 0xf = 000...0100 (0x4)
print(band(bnot(0xb), 0xf))  -- 4

print(bnot(0xb))             -- -11 (0 - 0xb)

See also Edit

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.