How can I write a serialized bit into a bit

Hi, Sorry but I beginig in xojo

How can I write a serialized bit into a bit,
For example I have the number &hAA and I want serialized this, and then put into a bit 0.
Can I use a function or somthing like that?

Look at the docs for the “bitsize” module. There are operations for shifting numbers etc.

You can also test a bit like this:

dim value as Integer dim bitNum as Integer = 5 dim bitIsSet as Boolean = (value AND pow(2,bitNum)) <> 0

And set a bit:

value = value OR pow(2,bitNum)

This is not very fast, though. So if you do this operations many times (in the millions), then it’ll be slow.

Not powerful, but a nice Quick’n Dirty solution. I am going to use it for some code where speed is no issue.
Thanks Thomas!

Thanks Thomas, :slight_smile:

You can speed it up considerably by pre-calculating the powers of 2.

Some initialization code:

bitval = 1
for i = 0 to 31
    powof2(i) = bitval
    bitval = bitval * 2
next

The main code:

dim value as Integer
dim bitNum as Integer = 5
dim bitIsSet as Boolean = (value AND powof2(bitNum)) <> 0

Oh, Thats great thanks Tim.