View Single Post
  #1  
Old 11-06-2006, 03:06 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Unsigned Bitwise Right Shift

lets pretend we're working with 8 bits.

11111111 = -1
-1 >> n = 11111111

I want to be able to do this:
-1 >> 7 = 00000001

In C++ this type of thing is handled by having an unsigned int.

In Java, (wow, something actually more flexible than C++?), this type of thing is handled by the >>>, >>>= operators (the extra >). It's unsigned right shift and unsigned right shift assignment.

so the above statement would actually look like this:

-1 >>> 7 (gives you 00000001)

So the addition of the unsigned right shift operator to gscript would be great.
Thanks.

Well, reading that you're checking compatibility with C code for bit shifts, it might actually be difficult to do this. C uses an unsigned type which would imply to always fill with zeros. You'd have no way of performing such an operation like this with signed types in C++. Meanwhile, a lot of scripting languages only have signed ints, so they use >>> when they want to accomplish this.
Reply With Quote