123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|709|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> Just out of curiosity...

Tue, 20 Mar 2007, 10:57
Blitz3Dman
Is it possible to write individual bits (booleans) to files using B3D? If so how?

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Tue, 20 Mar 2007, 11:23
mike_g
I'm pretty sure you cant

Intergers allocate 4 Bytes in Blitz. You could use an integer to hold up to 32 bool values using bit shifting if you really wanted to.

|edit| If you are writing to files then you can write Bytes, but not individual bits. |edit|
Tue, 20 Mar 2007, 16:24
Jayenkai
Yeah, as Mike suggests, you can use a combination of bitshifting and bytes to do what you need.

Or, use these handy GetBit and SetBit functions.



-=-=-
''Load, Next List!''
Wed, 21 Mar 2007, 18:03
Blitz3Dman
Thanks, been wondering how I'd do something like that for a while. Did you write the code yourself or find it?

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )
Wed, 21 Mar 2007, 18:22
mike_g
If you learn how bit shifting works then coding something like that is pretty straight forward. Shl shifts a bit left doubling its decimal value. Shr shifts right halving the value.

As an example: you can take a binary true state (1) and shift it left 7 times so it becomes 128. to get the value back shift right 7 times and you will be left with 1.

You can also cancel out any higher bit values by using the term 'And'. For example:

This line of code shifts a 4 byte colour value right by 16 bits, then uses 'and' to ignore the high 8 bits reserved for Alpha information. This leaves you with the red component of the colour.


Thu, 22 Mar 2007, 05:07
Blitz3Dman
I still haven't really learned how to use Shr and Shl. Probably ought to learn I suppose.

-=-=-
There are 10 kinds of people in this world -

( Insert 16 remarks about to what extent people know hex here )