Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Bit packing

Name: Anonymous 2014-01-28 23:42

does anyone have a working example of bit packing with negative numbers? I'm trying to pack three numbers, 8 bits each (from -255 to 255), by adding 255 to each number before I pack it, and just subtracting the same thing from it after I unpack. For some reason, I get weird ass errors around 0, like packing 0 but unpacking 256, and packing -1 and unpacking -256. I've tried everything I can think of and I have no idea what else to do.

local range = 8

local full = bit.lshift(1, range + 1) - 1
local half = bit.lshift(1, range) - 1

local a, b, c = -32, -64, -128

local x =
    bit.bor(
        bit.lshift( a + half, range*2 + 2),
        bit.lshift( b + half, range + 1),
        c + half
    )

local f = bit.band( x, full ) - half
local e = bit.band( bit.rshift( x, range + 1), full) - half
local d = bit.rshift( x, range*2 + 2) - half

Name: Anonymous 2014-01-29 0:06

8 bit number can hold only 256 different values, signed -127..128 unsigned 0..255

Name: Anonymous 2014-01-29 0:11

x itself caps at 32 bits I think, after I add half to each number I give it range + 1 bits, which in this case is 9 bits which should be 0-511

Name: Anonymous 2014-01-29 0:20

wtf is this language?

Name: Anonymous 2014-01-29 0:26

lua

Name: Anonymous 2014-01-29 0:38

maybe because of little endian, anyway better use C for bit packing

Name: Anonymous 2014-01-29 2:03

bit.lshift
`
>implying you need a function call for bit ops

My sides.

Name: Anonymous 2014-01-29 3:25

install BSD/Gentoo

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2014-01-29 4:20

Name: Anonymous 2014-01-29 8:45

>>9
>le kike bit manipulation

Name: Anonymous 2014-01-29 10:49

Check 'em

Name: Anonymous 2014-01-29 18:55

switched over to signed magnitude and got it to work, thanks tho

Don't change these.
Name: Email:
Entire Thread Thread List