Re: Bitwise operators?

2020-10-03 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Bitwise operators?

Thanks for the explanations. That made more sense and I was able to solve the problem at hand and learn something new in the process

URL: https://forum.audiogames.net/post/576858/#p576858




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-02 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Bitwise operators?

In Python, you can just use bitwise xor because booleans convert to integers.  You'll either need a ^ b or you'll need int(a) ^ int(b), but either way it is actually there.  I don't understand your attachment however.  It feels like if you need logical xor for sidescrollers, you're coding something like it's still C.  I think I've seen xor seriously used like 5 times ever, it's always a notable experience.Most languages don't use the English words.  It's not a trend by any means, and Python is the only one I personally know (but I think Ruby also does).  I'm just using them because I happen to know Amerikranian knows Python.

URL: https://forum.audiogames.net/post/576344/#p576344




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-02 Thread AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector


  


Re: Bitwise operators?

So programming languages are moving away from the logical operators and toward the English words and / or, fwict. The only loss from this (other than some disk space) is how the operators correspond to their bitwise counterparts.Both & and && are doing the same thing, in terms of how they go from input to output. && is for booleans, and & is for sequences of bits, but both return True / 1 if and only if both operands are True / 1, False / 0 otherwise.Same with || and |. Both return True / 1 if either operand is True / 1, only False / 0 if neither is True.And really, True and False are just special cases of 1 and 0. They just plain were 1 and 0, back in the day.So = is to == as & is to &&, as | is to ||, as ! is to ~, and in theory ^ and ^^ but I'm not sure if anyone lets you use ^^ for logical xor.Basically, for every combination of inputs, there's an operator that returns True / 1. Except False and False / 0 and 0, but there is a logic gate for that in your CPU and you can just say not and (aka nand) for that, if you really need it. (I actually use x&~y quite a bit, just to turn off specific bits, but I don't think that uses nand under the hood? Well, OK, there's a proof that you can use nands to get all the other operations, so anything could be using nand under the hood, but I digress.).I I suppose you use the logical operators when you need a boolean. You use the bitwise operators when you want a number. The key thing is understanding how numbers are sequences of booleans. If you think of an int as something like an array of bits, it makes more sense.And like Camlorn said, the ability to work with binary / hexadecimal is essential to this. 1&2 == 0, because 1 and 2 have no bits in common. 1&3 == 1, because they only have the 1 bit in common. And 1|2 == 3, just like 1|3, because the 1 and 2 bits are there in both cases, but no others.The thing that threw me was realizing that we have a bitwise xor, but no one ever teaches logical xor. Then I discovered that Python does not have a logical xor, but angelscript does, and xor is really useful for side-scrollers. Ah, well. What's a little extra code? That's how everything works, isn't it?

URL: https://forum.audiogames.net/post/576288/#p576288




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Bitwise operators?

Yeah. I don't think it's important for us to explain that here unless Amerikranian specifically asks for it.  Just, thinking about them like that is only first-level understanding.  Not on your part, but in terms of learning them, it's not necessarily really a good way to think about it.I think better to say that & does what and does to two boolean expressions, but to every pair of bits; | does what or does to two boolean expressions, but to every pair of bits, etc.  Unfortunately there's no real equivalent of ^ that works on booleans, but ~ does what not does to a boolean _expression_ to every bit in the input, and ^ is roughly equivalent to (a and not b) or (b and not a) being applied to every pair of bits.

URL: https://forum.audiogames.net/post/576115/#p576115




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-01 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Bitwise operators?

@4, no, its not, but its typically how they're employed. Wikipedia does a much, much better job at explaining how they actually work than I can, even providing a mathematical equivalent to each operator. But that's Wikipedia for you. Lol

URL: https://forum.audiogames.net/post/576089/#p576089




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-01 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Bitwise operators?

@4, no, its not, but its typically how they're employed. Wikipedia does a much, much better job at explaining how they actually work than I can. Lol

URL: https://forum.audiogames.net/post/576089/#p576089




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Bitwise operators?

@3Think it's important to clarify that though you are explaining how and why someone might use them, you're only explaining uses and that's not actually a description of what they do.

URL: https://forum.audiogames.net/post/576073/#p576073




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-01 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: Bitwise operators?

The << operator is a power-of-two multiplication. It is used for selecting a bit (e.g.: if you have a 32-bit number and each bit means something, and you want to select bit 5 so you can set it, you do 1 << 5, not 5). The >> operator is a power-of-two division and is used for isolating bit sequences. As Camlorn said, << is equivalent to 2**x, and >> is equivalent to x/(2**n).The | operator sets bits unconditionally. If you do 0|(1 << 6), and you have an 8-bit integer, you get back an integer with bit six set. (As with all things in computing, bits are 0-based, so if you want to reference bit 32, you refer to bit 31, not 32.)The & operator checks to see if a bit is set. If you have a 32-bit integer and you want to see if bit 18 is set, the _expression_ x & (1 << 18) will tell you this. In C, you can do if (x & (1 << 18)), but in most other languages you must check to see if the result is explicitly greater than zero because you will get back an integral value. For instance, if you have a 32-bit integer with all bits set (0x in hex), (0x & (1 << 18)) yields 0x4, or 262,144, therefore bit 18 is set.The ^ operator is the exclusive or operator, also known as XOR. XOR will toggle bits. If you have a 64-bit integer and bit 60 is set, x ^ (1 << 60) will clear that bit, and doing that operation again will set that bit. You can make an entire integer zero by XORing it with itself, but note that XORing it with itself again will set (all) bits within that integer.Finally, the ~ operator is the bitwise not operator. The ~ operator determines the bitwise compliment of each bit; that is: if there is a bit that is one, its compliment is zero; if a bit is zero, its compliment is one. In other words, ~x is equivalent to  the twos compliment of x minus one. Note that the bitwise not of an unsigned integer is its "mirror reflection" of the number across the half-way point of the range of the unsigned integer.

URL: https://forum.audiogames.net/post/576064/#p576064




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Bitwise operators?

2020-10-01 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Bitwise operators?

Wrap the results in bin().  That will let you see the bits rather than the base 10 integer.<< and >> are shifts and are generally an exception to the rule I'm about to explain.  << takes the string bin() returns and adds the specified number of 0s on the end.  >> chops off the specified rightmost digits.  These are effectively multiplication and divisions by powers of 2: x << n = x * (2**n), x >> n = x / (2**n).The rest can be worked out by learning what they do to a single bit.  Once you know that, it does it to all bits in the arguments, assuming that any missing bits in the smaller number are 0.You're confused because you don't know how to convert from base 10 to base 2 in your head.  I'd practice that some.  Also, you should practice going from base 2 to base 16.  Base 2 to base 16 (also known as hex) is actually easier, because unlike base 10 you can just consider the binary number 4 bits at a time and don't have to look at the others.  But I will leave you to the internet on that one, I don't particularly feel like typing a tutorial with a bunch of tables unless you really, really need me to.

URL: https://forum.audiogames.net/post/575995/#p575995




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-05 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: bitwise operators

@16, yep. They're useful for packing a ton of flags into a single variable, which is a very nice thing. https://stackoverflow.com/questions/209 … -operators

URL: https://forum.audiogames.net/post/438746/#p438746




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-05 Thread AudioGames . net Forum — Developers room : pranam via Audiogames-reflector


  


Re: bitwise operators

Hi,I'm also learning C but I haven't encountered bitwise operators. I will look on the subject. Are they of any use other than shifting and formatting your output?

URL: https://forum.audiogames.net/post/438701/#p438701




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-05 Thread AudioGames . net Forum — Developers room : pranam via Audiogames-reflector


  


Re: bitwise operators

Hi,I'm also learning C but I haven't encountered bitwise operators. I will look on the subject.

URL: https://forum.audiogames.net/post/438701/#p438701




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-04 Thread AudioGames . net Forum — Developers room : r3dux via Audiogames-reflector


  


Re: bitwise operators

@kaigoku - Entirely agree with you, and curiosity is king - which is why I included a reference to a great book on a variety of methods to go about 'bit-twiddling' if that's something of interest 

URL: https://forum.audiogames.net/post/438565/#p438565




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-04 Thread AudioGames . net Forum — Developers room : r3dux via Audiogames-reflector


  


Re: bitwise operators

@kaigoku - Entirely agree with you, and curiosity is king - which is why I included reference to a great book on a variety of methods to go about 'bit-twiddling' if that's something of interest 

URL: https://forum.audiogames.net/post/438565/#p438565




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-04 Thread AudioGames . net Forum — Developers room : kaigoku via Audiogames-reflector


  


Re: bitwise operators

Post 12 and 13, you make valid points in that perhaps it is not worth optimizing using bit manipulation if you have a nice compiler that will do everything for you behind the scenes. Especially since most of the bit manipulation operators are abstracted away from machine-level implementations due to overhead, register allocation, etc. However, it's obvious that OP is just curious about how these things can be applied. It never hurts to be curious.  I will say, OP, just keep that in mind when you want to use bit manipulation in higher level programs you decide to write that it might not be worth the headache. These are definitely tricks that an embedded systems engineer could use to significantly improve certain aspects of a program. Even at that, sometimes, there are compilers for really well-known microcontrollers, and if you have the privilege of having a nice OS, then you might not even have to touch them in any case. Bit manipulation certainly facilitates a better understanding of computers at a much lower level. IMO, a nice intro to Electrical Engineering. 

URL: https://forum.audiogames.net/post/438556/#p438556




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-04 Thread AudioGames . net Forum — Developers room : r3dux via Audiogames-reflector


  


Re: bitwise operators

TL:DR - Don't optimise via bitfields, let the compiler and the computer do its job.Sometimes bitfields are of use (i.e. simple powers of 2, some if-this-then-that cases), but the vast majority of the time they make a simple task more complicated, the code becomes significantly harder to understand (and hence modify and debug) - and as such they are very prone to bite you in the ass.If you want a book on bit-twiddling (and this is one I actually own), try: http://www.hackersdelight.org/I'd caution anyone thinking they can save a few cycles by raw bit manipulation that they may also cost themselves a few hours if not days or weeks later down the track figuring where their bit-twiddling didn't work as expected in corner-cases because they bypassed the normal checks-and-balances built into the programming language primitives they were working with.Also, only ever optimise the core code than runs 95% of the time. If you can make something 1ms quicker and it runs 60 times per second then you're up 60ms * 60 minutes * 24 hours = 86,400ms = 1,440 seconds = 24 minutes per day. If you optimise something by 5000ms (5000 times more!) that runs once per day then you gain 5 seconds, and you probably spent at least a few hours 'optimising' it.

URL: https://forum.audiogames.net/post/438553/#p438553




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-04 Thread AudioGames . net Forum — Developers room : r3dux via Audiogames-reflector


  


Re: bitwise operators

TL:DR - Don't optimise via bitfields, let the compiler and the computer do its job.Sometimes bitfields are of use (i.e. simple powers of 2, simple if-this-then-that cases), but the vast majority of the time they make a simple task more complicated, the code becomes significantly harder to understand - and as such they are very prone to bite you in the ass.If you want a book on bit-twiddling (and this is one I actually own), try: http://www.hackersdelight.org/I'd caution anyone thinking they can save a few cycles by raw bit manipulation that they may also cost themselves a few hours if not days or weeks later down the track figuring where their bit-twiddling didn't work as expected in corner-cases because they bypassed the normal checks-and-balances built into the programming language primitives they were working with.Also, only ever optimise the core code than runs 95% of the time. If you can make something 1ms quicker and it runs 60 times per second then you're up 60ms * 60 minutes * 24 hours = 86,400ms = 1,440 seconds = 24 minutes per day. If you optimise something by 5000ms (5000 times more!) that runs once per day then you gain 5 seconds, and you probably spent at least a few hours 'optimising' it.

URL: https://forum.audiogames.net/post/438553/#p438553




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector


  


Re: bitwise operators

I think truth tables are more annoying than helpful in audio, and just each case as a statement would be easier to follow.No, there is no difference between those two statements.  Bitshifting is more useful when the power of 2 in question is variable. It's faster and easier to type x<

URL: https://forum.audiogames.net/post/438172/#p438172




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

ok I think I grasped the setting and removing of flags, but just to be sure that it's the correct way, let's post it here #include
#include
int music, state=1;
void toggle(char option[10])
{
if (option=="playing")
{
music^=state;
}
else if(option=="repeat")
{
music^=state<<1;
}
}also, is there any difference between these 2 statements?music^=state<<1;

music^=state*2;

URL: https://forum.audiogames.net/post/438151/#p438151




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

Thanks a lot kaigoku, i'l check those things out and will see problem is, I live in a country where blind people don't study math at all beyond very basic stuff such as addition and subtraction, much less other sciences. So probably this is partly why I have dificulty with those advanced concepts, and i'l have a long road ahead of me if I continue.I have worked with higher level programming languages before, but i'd rather understand what's going on behind the scenes than doing things the easy way, unaware of how do things work exactly, even if it means spending long periods of time trying to make sense of things.

URL: https://forum.audiogames.net/post/438116/#p438116




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

Thanks a lot kaigoku, i'l check those things out and will see problem is, I live in a country where blind people don't study math at all beyond very basic stuff such as addition and subtraction, much less other sciences. So probably this is partly why I have dificulty with those advanced concepts.I have worked with higher level programming languages before, but i'd rather understand what's going on behind the scenes than doing things the easy way, unaware of how do things work exactly, even if it means spending long periods of time trying to make sense of things.

URL: https://forum.audiogames.net/post/438116/#p438116




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

Thanks a lot kaigoku, i'l check those things out and will see problem is, I live in a country where blind people don't study math at all beyond very basic stuff such as addition and subtraction, much less other sciences. So probably this is partly why I have dificulty with those advanced concepts.I have worked with higher level programming languages before, but i'd rather understand what's going on behind the scenes than doing things the easy way, unaware of how do things work exactly.

URL: https://forum.audiogames.net/post/438116/#p438116




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

Ok i think I got it!I have something like:int music, state=1;
void toggle(char option[10])
{
if (option=="playing")
{
music^=state;
}
else if(option=="repeat")
{
music^=state<<1;
}
}out of curiosity, is there any difference between those 2 statements in terms of efficiency and other stuff?music^=state<<1;

music^=state*2;

URL: https://forum.audiogames.net/post/438115/#p438115




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : kaigoku via Audiogames-reflector


  


Re: bitwise operators

Post 5, truth tables can be expressed as regular row-column tables. I think Wikipedia has a nice entry on truth tables you can read. On the web, they can usually be represented in standard HTML tables. These are simple tables that have headers such as, x, y, x, x|y, x^y, etc. Then, for each row, you have the different combination of bits that x and y can take on. I would show you an example, but not sure if you can make tables in BB code or whatever this forum system uses. That, and I am kinda in a hurry. lol A quick example of using bitwise operators to do arithmetic is by using AND operator on bits for carry bit, and XOR on the two bits to add, shift left 1 position to the left, and add. There is a very interesting implementation here: https://www.geeksforgeeks.org/add-two-n … operators/ . It uses a recursive technique, which is not very efficient, but it gets the point across. Also, a good article to read on Wikipedia is on the adder circuit. Keep in mind that at a circuit level, the ALU only has logic gates available to it. A good intro to digital logic or computer architecture might be really useful. Hope some of this is helpful and it doesn't go over your head. Users of higher-level programming languages don't usually have to concern themselves with these things, but bitwise operations and registers and all that fun stuff is essential to how programming languages can do what they do so easily. If you take a computer science cirriculum, much of this is covered in an Intro to Digital Logic course, or Computer Organization course. And the real fun stuff is if you dive into Electrical Engineering and you get to play with FPGAs and microprocessors, not to be confused with microcontrollers.

URL: https://forum.audiogames.net/post/438111/#p438111




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-02 Thread AudioGames . net Forum — Developers room : kaigoku via Audiogames-reflector


  


Re: bitwise operators

Post 5, truth tables can be expressed as regular row-column tables. I think Wikipedia has a nice entry on truth tables you can read. On the web, they can usually be represented in standard HTML tables. These are simple tables that have headers such as, x, y, x, x|y, x^y, etc. Then, for each row, you have the different combination of bits that x and y can take on. I would show you an example, but not sure if you can make tables in BB code or whatever this forum system uses. That, and I am kinda in a hurry. lol A quick example of using bitwise operators to do arithmetic is by using AND operator on bits for carry bit, and XOR on the two bits to add, shift left 1 position to the left, and add. There is a very interesting implementation here: https://www.geeksforgeeks.org/add-two-n … operators/ . It uses a recursive technique, which is not very efficient, but it gets the point across. Also, a good article to read on Wikipedia is on the adder circuit. Keep in mind that at a circuit level, the ALU only has logic gates available to it. A good intro to digital logic or computer architecture might be really useful. Hope some of this is helpful and it doesn't go over your head. Users of higher-level programming languages don't usually have to concern themselves with these things, but bitwise operations and registers and all that fun stuff is essential to how programming languages can do what they do so easily.

URL: https://forum.audiogames.net/post/438111/#p438111




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-01 Thread AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector


  


Re: bitwise operators

I used bitwise in C++ once for a maze generation system. Instead of having lots of boolean values (thereby wasting precious memory) I used a single 32-bit integer (or was it 64) to represent all the flags for each cell. For example, I used something like if ((cell.flags)==1) to test if it was a door and so on. That same integer also held directional flags as well, so it was used for quite a lot of things. To add a flag, I used the &= operator, which is identical to doing cell.flags = cell.flags & flag. For removing bits/flag negation, I used the &= operator combined with the ~ operator, making it cell.flags&=~flag. A good way of describing bit shifts is to imagine your bits as an infinite stream of ones and zeros. This infinite stream is your programs address space, since bitwise operations can happen anywhere in the address space (and if your writing an OS driver or kernel, it can happen *anywhere*). If you bit shift to the left (x<>y), the x-bit becomes the y-bit, the exact opposite of the bit shift to the left. (Please correct me if I am wrong; I'm attempting to paraphrase this topic when I was reading low-level assembly language documentation on developing OS kernels -- I tried and failed at that, BTW. Always triple-faulted, and I could never find out why, since my kernel (which I only wanted to print "hello world") didn't support serial ports. Perhaps I should try that again sometime.)

URL: https://forum.audiogames.net/post/438069/#p438069




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-01 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

fundamental question actually I suppose i'm familiar with binary as well as what each operator does. I mean how & returns the bits that are true in both operands, how | | returns the bits that are true in one of the 2 given operands and so on, I just fail to figure out how to use them to accomplish something useful LOL.

URL: https://forum.audiogames.net/post/438039/#p438039




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-01 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

fundamental question actually I suppose i'm familiar with binary as well as what each operator does actually. I mean how & returns the bits that are true in both operands, how | | returns the bits that are true in one of the 2 given operands and so on, I just fail to figure out how to use them to accomplish something useful LOL.

URL: https://forum.audiogames.net/post/438039/#p438039




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-01 Thread AudioGames . net Forum — Developers room : leibylucw via Audiogames-reflector


  


Re: bitwise operators

I suppose this might be a dumb question, but are you familiar with binary? You'll need to know it in order to grasp bitwise operations.

URL: https://forum.audiogames.net/post/438038/#p438038




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-01 Thread AudioGames . net Forum — Developers room : goran via Audiogames-reflector


  


Re: bitwise operators

Thanks guys! I was actually about to abandon this concept for now as it was a bit more complicated than what I have worked with so far, since I had no idea about its use and that gave me little incentive to bother with it. Although some of what you guys have wrote are too advanced for me at this stage to make complete sense of, but at the same time, you have given me a lot of things to look up, take note of for later, and/or look forward to  .A couple more questions (I have a feeling that they will be far from my last questions):kaigoku mentioned truth tables to work with for  practicing  the use of those operators, and I have seen other people refer to them as well while explaining logical operations and such. I have tried to look it up, but I haven't been able to grasp the making of it so far, not sure if it's because of the inaccessibility of the way they are represented, or i'm to blame myself  . So is there any specific resource or way with which the construction of truth tables can be made/learned easier?also, Could you refer me to or give me a very simple practical example of how the bitwise operators can be used to do arithmetic operations or any other operation which is easy to understand for a newbie? Code example I mean.Thanks again for bearing with my noob questions 

URL: https://forum.audiogames.net/post/438035/#p438035




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-06-01 Thread AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector


  


Re: bitwise operators

If you need more than 4 booleans in a class, struct, or whatever, it's easier to use an int, using the bitwise operators to interact with the bits. This is also helpful when you don't know in advance how many boolean flags you'll need.There are some other uses you might come across in game-related libraries, related to efficiently storing data for collisions, or complex properties that can't be reduced to booleans. If I remember correctly, Box2d has two ints for specifying arbitrary custom types for objects. I forget the exact rules, but iirc it's something like only let the objects interact if x.mask1 & y.mask2 is nonzero. This let's you be as complex or simple as you want for a wide variety of projects.Things I use bitwise operations for all the time:- I had a class for input configurations (keyboard, joystick, whatever) that assumed something like your typical game controller, with 6-12 buttons. Using bits for this allowed me to use the same constants for controls and movelists.- Movelists. Since many of my games do some fighting game-like movelists, I use ints to define what state the characters are in, and bits to map those to commands. You could just use something string-based, but somehow this has worked much better for me.- Lists of properties that could change later. Continuing with the fighting example, a move might involve fire, might use a common set of battlecries, might need to track the sound or not, might be unstunnable, unblockable, cancelable, seeking, weightless, etc, etc. As the game develops, some new properties might become necessary or useful. A giant pile of booleans isn't just inefficient for the machine; it's a time-waster, confusing to navigate, takes up space in your code that affects readability, and if you do things like by-hand cloning or serialization, you'd have to change that every time you add or modify a property. On the other hand, you can just declare "int flags;", and all you need to do is add constants (if you don't just memorize the values, but who does that?).- Unlockables or variable lists of playable characters. I'll use EC as an example. Each level has a certain list of characters who can be used in that level, and sometimes that list changes. An array or linked list might be viable, but I was getting the list only when needed, so just returning an int was simpler.- Voxels. I don't have the patience to make a new map editor for every game that requires a different format, so whenever I can just make the map into an array of strings, or at least load from one, that's preferred. That does limit what I can do in terms of 3d, though. One solution for this is to map an int to each unique char on the map, and have that int represent the vertical stack. This lets me make maps with a notetaker whereever I happen to be at the time, without being restricted to 2 dimentions.- Aiui, mainstream games have used bitmasks to speed up hit detection. Kinda irrelevant if you're using a super optimized physics engine on a super optimized machine, but that's a thing.- Efficiency, if you have memory limits. You'd be surprised how much you can fit into 8 bits.- Some libraries do things like represent colors as a single int. Swamp maps do this. If you work with these, you'd need to use bitwise operators to work with red/green/blue individually.

URL: https://forum.audiogames.net/post/437943/#p437943




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-05-31 Thread AudioGames . net Forum — Developers room : kaigoku via Audiogames-reflector


  


Re: bitwise operators

Yes, there are many uses for them. For example, you can use bitwise operators to add, multiply, subtract, and divide numbers. This saves on CPU cycles, and it's an efficient way to represent data without using multiple integers. I should clarify that as the name suggests, bitwise operators operate on the level of bits (binary digits). So, building truth tables and practicing with 32-bit integers is always helpful in understanding how to manipulate data using this method. If you know what you're doing, you can use them to write simple conditionals involving numbers by eliminating checks altogether and self-evaluate for flags. These things are especially used in embedded systems in where you have a microcontroller with limited memory and you want to optimize performance and reduce footprint. If you study assembly languages, some of this might make more sense. I've worked on embedded systems before, and believe me, if you know how to use bitwise operators and other features of C (unions, bit structs, etc), you will be greatly valued.

URL: https://forum.audiogames.net/post/437841/#p437841




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: bitwise operators

2019-05-31 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: bitwise operators

It depends. On some architectures bitwise operations can be more efficient, though again it depends. So, basically a way to optimize performance.

URL: https://forum.audiogames.net/post/437835/#p437835




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector