Fandom

Pico-8 Wiki

Shr

162pages on
this wiki
Add New Page
Comments0 Share
shr( num, bits )

Shifts the bits of a number to the right.

num
The number.
bits
The number of bits to shift.

The shr() function takes a number and a bit count, and returns the result of shifting the bits of the number to the right by that count.

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. Bit shifting uses the entire number representation. (See examples below.)

Examples Edit

-- 8 = 00001000 binary
-- 1 = 00000001 binary
print(shr(8, 3))  -- 1

-- 1.000 = 0001.0000 binary
-- 0.125 = 0000.0010 binary
print(shr(1, 3))  -- 0.125

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.