Answer the question
In order to leave comments, you need to log in
Binary translation or operations with bitwise shifts?
I get an array, for example {1, 3, 0, -57, 0, 0, 79, 11}
where -57 is what engines are on.
if we translate -57 into binary code "0xC7 = 11000111" I can find out what is enabled now 1, 2, 6, 7 and 8 engine
It seems like something like this, how can I check in the code to find out what is enabled now, that is,
specify engine number 5 look at bit 5 which is now = 0
and display.
That is, the feeling that it should be something like this
-57 << 5
and the answer will be 0
Who can show how to correctly write such a problem with the number -57, because I haven’t reached this topic yet, but I’m only learning the language?
Answer the question
In order to leave comments, you need to log in
First you need to clearly formulate the problem so that others can understand it. If you need to check if the nth bit in a number is set, it's done like this:if (x & (1<<n)){что-то там}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question