Answer the question
In order to leave comments, you need to log in
Please explain this example in bitwise operations, why is Math.pow here?
The meaning of the method is simple: you need to show 64 bits and only 1 where necessary, depending on the parameters that were passed to the method. You can think of these 64 bits as an 8*8 map.
/*
ABCDEFGH
┌────────
1│10000000
2│00000000
3│00000000
4│00000000
5│00000000
6│00000000
7│00000000
8│00000000
*/
В метод залетает буква и цифра - А1 например ( как в примере выше ), там и должна быть единица.
public static void shoot(String shot) {
int columns = (int) shot.charAt(0) - 64;
int rows = Character.getNumericValue(shot.charAt(1));
int sdvig = 8 * ( 8 - rows);
long firstValue = (long) Math.pow(2, 8 - columns );
System.out.println(Long.toBinaryString(firstValue << sdvig));
}
shoot("A1");
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question