# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### DarkBASIC Discussion / set of functions for manipulating bits(emulates the bitwise operators)

Message
Posted: 6th Sep 2011 21:49 Edited at: 6th Sep 2011 21:50
hi,

This is a set of functions for manipulating bits:
- rotate bits left/right
- shift bits left/right
- XOR
- NOT

I hope it will be useful to someone

DirectX 9.0c (February 2010)/ DBClassic v1.13
Posted: 26th Sep 2011 21:35
Nice functions
I made XOR myself, it's very useful

Does this code work?
if (2^31 = -1) then print "TRUE" else print "FALSE"
wait key : end

i.e. does DB know that an integer of -1 is actually 11111111...? Without using bitwise operators?

For clarity I think it would be better to use <=31 rather than <32, but maybe I'm just easily confused

Posted: 27th Sep 2011 11:07 Edited at: 27th Sep 2011 11:11
hi OBese87,

10000000000000000000000000000000 = 2^31
11111111111111111111111111111111 =(2^32)-1

so, this:
if (2^31 = -1) then print "TRUE" else print "FALSE"
wait key : end
code return "FALSE" because (2^32)-1 <> 2^31

Quote: "i.e. does DB know that an integer of -1 is actually 11111111...?"

of course!

Quote: "For clarity I think it would be better to use <=31 rather than <32"

you're right, I should have done it that way.

DirectX 9.0c (February 2010)/ DBClassic v1.13
Posted: 28th Sep 2011 02:10
Quote: "code return "FALSE" because (2^32)-1 <> 2^31"