• No bitwise not? Only AND, OR, Shift left and Shift right?
    7 replies, posted
Is there anyway I can do a bitwise NOT in GLua? I need to be able to easily add and remove flags in a variable and I'm not sure how to easily remove it without the NOT. Any help is awesome, thanks!
[url]http://wiki.garrysmod.com/?title=Bitwise[/url] Thats a Yes, There is no NOT
[QUOTE=ColdFusion;28845494][url]http://wiki.garrysmod.com/?title=Bitwise[/url] Thats a Yes, There is no NOT[/QUOTE] I know that already, that is why I am asking if anyone has another way to do it.
Not sure about this. [lua]function bnot(a,b) return (a&b==0) end[/lua] I've never used bitwise not, so I'm not sure if that's the proper functionality.
[QUOTE=FlapadarV2;28845801]Not sure about this. [lua]function bnot(a,b) return (a&b==0) end[/lua][/QUOTE] Nope, a bitwise not would turn, say, an 8bit number 01000101 into 10111010
How would you "not 01000101" if you don't know the length? That could as well be 00000 ... 00000000001000101, right? Only way you can not is do something like [B]return 11111111-01000101[/B]
[lua] function bnot(a) return 0xffffffff-a end [/lua] [editline]meh[/editline] Or to just remove a flag [lua] FLAGS = FLAGS-(FLAGS & flag) [/lua]
Normally it is taken care of by your processor directly on a memory value. I have seen code back in the day that converts a number into binary and does it manually but it is excessively slow in comparison but I don't need it to be fast. I just wanted an easy solution if it was known.
Sorry, you need to Log In to post a reply to this thread.