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.

Author
Message
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 31st Mar 2011 23:51
Let's say I wanted to write a system similar to DBPro's camera masking commands, How would I go about determining the values which went onto said mask. Here is what I have tried:


But as you can see, It does not work as I expected. I am new to the whole bit-wise operation thing so what am I missing/doing wrong?
bitJericho
23
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 1st Apr 2011 00:16 Edited at: 1st Apr 2011 00:24
Here's a tutorial for bitflags.

http://weblogs.asp.net/wim/archive/2004/04/07/109095.aspx

Actually, that's a pretty confusing example. Here's some simple code



[center]
Join the TGC Group!
http://tehcodez.groups.live.com
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 1st Apr 2011 00:45 Edited at: 1st Apr 2011 00:48
Quote: "CamMask=(1^2)||(2^2)||(3^2) `cameras 1+2+3

for Cam=1 to 32
//See if the camera was included in the mask
CamIncluded=CamMask && (Cam^2)
if CamIncluded>0
print "Camera ",Cam," Was Included in the mask!!"
endif
next Cam

wait key
"

Actually... What you really want to do is this:

From the rightmost bit, the Nth bit to the left of it IS NOT n^2, but 1*2^n. So 1|2|4|8=(1111 base 2)
[edit]
Also, I think 1||2=1, because that's BOOLEAN "or", not bitwise "or". With dbpro, I think a number greater than 0 is true, and 0 is false.

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Apr 2011 21:29
DBPro doesn't have a boolean OR - it has bit-wise only, so using || is correct.

As you've pointed out, the problem was the 'Cam^2' - that should have been '2^Cam' instead. The exact same problem exists in the first line of the code too.



You can also generate and test the mask using << and >> instead


Finally, there are also some bit commands in my plug-in set that can also be used instead of the bitwise&power operators:


Login to post a reply

Server time is: 2026-07-11 14:57:00
Your offset time is: 2026-07-11 14:57:00