Re: I need the speed

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lucius L. Hilley III writes:
> Please clarify how the remaining bits in bitbuffer will not be lost
> and how the bits to be added are being stored into bitbuffer.

I hope the following will be a bit clearer and more accurate.
Warning: I've checked the syntax, but I haven't actually run or tested
the following code.

=================================================================

constant SHIFT8 = power(2, 8)

atom bitbuffer  -- always >= 0, can hold about 30 bits
bitbuffer = 0

integer bitbufferlen  -- number of bits currently in the buffer
bitbufferlen = 0

integer fn
fn = open("datafile", "wb") -- remember to open for binary write

procedure add_bits(integer value, integer len)
-- Add a value to the buffer. Value is len bits long and >= 0.
-- len is 0 to 7.

    -- store len in buffer:
    len = len * power(2, bitbufferlen) -- shift left by bitbufferlen bits
    bitbuffer = or_bits(bitbuffer, len) -- OR it into buffer
    bitbufferlen = bitbufferlen + 3

    -- store value in buffer:
    value = value * power(2, bitbufferlen) -- shift left
    bitbuffer = or_bits(bitbuffer, value)
    bitbufferlen = bitbufferlen + len
end procedure

procedure write_bits()
-- Write a byte from the buffer to the file.
-- The low order 8 bits are removed.
    puts(fn, bitbuffer) -- only low-order 8 bits are written
    bitbuffer = floor(bitbuffer / SHIFT8)
    bitbufferlen = bitbufferlen - 8
end procedure

=======================================

Regards,
  Rob Craig
  Rapid Deployment Software

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu