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)

Author
Message
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
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
- READBIT

I hope it will be useful to someone


DirectX 9.0c (February 2010)/ DBClassic v1.13
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
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

Join DNG today! We are a game development team open to all. Visit our Headquarters to learn more.
Silverman
13
Years of Service
User Offline
Joined: 18th Jan 2007
Location: France
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
Libervurto
14
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 28th Sep 2011 02:10
Quote: "code return "FALSE" because (2^32)-1 <> 2^31"

Oops I made a mistake there with 2^31 instead of 2^32-1.

Are numbers written as little-endian? I remember something about memblock data that is little-endian. You could write a function to switch from little to big-endian.

Join DNG today! We are a game development team open to all. Visit our Headquarters to learn more.

Login to post a reply

Server time is: 2020-08-15 11:47:59
Your offset time is: 2020-08-15 11:47:59