Anyone got any code to access a file bit-by-bit?

BlitzMax Forums/BlitzMax Programming/Anyone got any code to access a file bit-by-bit?

Damien Sturdy(Posted 2008) [#1]
Need to modify an SWF file and can't get the RECT structure to read properly,

So I need a way to write the following to a file,

N1[5 bits]: Number of bits used in the following 4 fields.
N2[n1 bits]
N3[n1 bits]
N4[n1 bits]
N5[n1 bits]



I actually have some code to read it (seems to work on individual values with known answers, but when run with the SWF file returns odd results.)

Anyone got anything lying around I could look at?

Ta.


Dreamora(Posted 2008) [#2]
you can not access it like that.
you must read it in a byte at least and use shl / shr and & $xxxx to get the single bits you want


Damien Sturdy(Posted 2008) [#3]
Yeah I am aware of that. ;-)

Anyway, i got the code working, still isn't able to write a valid SWF header though. No matter!


TomToad(Posted 2008) [#4]
Make sure the bit order is correct.

Best thing to do is get a SWF file containing data you know and look at how it's stored with a hex editor.


ImaginaryHuman(Posted 2008) [#5]
Make it a little endian stream?


Damien Sturdy(Posted 2008) [#6]
Make it a little endian stream?



Trust me, i've tried all this.

I got around the problem in te end by patching the phone with the wrong res with data from a file that had the correct res. itworked.

My binary read/write code worked, they were just stored oddly in the file. Waste of time too since the "fix" I was hoping to apply didn't work!

Anwyay, disregard this thread from here, i have resolved the issue. :-)