uint value comparison for a 32 layer system (GameDev)
Hello. I'm looking for a way to see if these toggles are on or off by comparing the total value of the uint.
Description
How it works is that if the toggle is on, it returns the corresponding uint value and if it is off it returns zero. If we take top row for example, it goes from and index of 31 backwards to an index of 1. All these values that the toggles represents get added on top of each other and that results in the actual uint value. Taking the toggles on the top row as an example again, having them all toggled on it return
Example
Lets take 5 toggles each respresenting 1, 2, 4, 8 and 16 respectively.
if all toggles are on it should give back the total number of all the numbers the toggle represents. If all toggles are off it should return zero. If the first toggle is on and the rest are off it should return 1. If the first and the third toggle (1 and 4) are active it should return a total number of 5.
What I Did
What I did now was to create a switch and check every possible number, but I dont think it is a smart way to do this. it was the only way I knew that would work;
What I am hoping for
I was looking for a better/more elegant way to approach this problem. If anyone can point me in a direction, I'll be grateful. Thanks for reading.
Description
How it works is that if the toggle is on, it returns the corresponding uint value and if it is off it returns zero. If we take top row for example, it goes from and index of 31 backwards to an index of 1. All these values that the toggles represents get added on top of each other and that results in the actual uint value. Taking the toggles on the top row as an example again, having them all toggled on it return
uint.MaxValue and if they are all toggled off it returns 0.Example
Lets take 5 toggles each respresenting 1, 2, 4, 8 and 16 respectively.
if all toggles are on it should give back the total number of all the numbers the toggle represents. If all toggles are off it should return zero. If the first toggle is on and the rest are off it should return 1. If the first and the third toggle (1 and 4) are active it should return a total number of 5.
What I Did
What I did now was to create a switch and check every possible number, but I dont think it is a smart way to do this. it was the only way I knew that would work;
What I am hoping for
I was looking for a better/more elegant way to approach this problem. If anyone can point me in a direction, I'll be grateful. Thanks for reading.

