<< - оператор сдвига влево: он сдвигает двоичное число, хранящееся в компьютере, влево. Например, 9 в двоичном формате равно 1001. 9 << 2 составляет 100100 в двоичном формате (36), потому что он сдвигает его влево и добавляет 0 в конце. 1 << n - это то же самое, что Math.pow (2, n), за исключением того, что это намного быстрее и лучше в целом, а также возвращает int, а не double.
- Hızlı yanıt
- Arama sonuçları
- freecodecamp.org news/java-operator-and-or-…In this article, we learned how to use the bitwise & operator in Java and how the operation is carried out to give us a result.
- silentkiller17905.medium.com java-operator-…Here, the + operator is used to add two variables a and b. Similarly, there are various other arithmetic operators in Java.
- yerch74.github.io w3schoolsrusbwou/java/java_…Java Файлы Java Создание/Запись файлов Java Чтение файлов Java Удаление файлов. ... Java делит операторы на следующие группы
- digitalocean.com community/tutorials/addition-…It’s the Addition assignment operator. Let’s understand the += operator in Java and learn to use it for our day to day programming.
- blog.geekster.in java-operator/Operators play a crucial role in programming languages, including Java, as they allow us to perform operations on data and control the program flow.
- russianblogs.com article/34912092707/Операторы, обычно используемые на языке Java, могут быть разделены на следующее: Ø Арифметический оператор.
- stackoverflow.com questions/1991380/what-does-the…As for integer exponentiation, unfortunately Java does not have such an operator. You can use double Math.pow(double, double) (casting the result to int if necessary).
- javarush.com groups/posts/ternarnyj-operatorТернарный оператор - 1 “Тернарный” в переводе означает “тройной”. Это альтернатива условному оператору if-else, который тебе уже знаком.
- practicum.yandex.ru blog/operatory-java/Чтобы понять, как работают операторы Java, нужно хорошо представлять, как устроен этот язык программирования.
- sky.pro wiki/java/funktsional-operatora-v-java-…Оператор `^` в Java обозначает логическое исключающее ИЛИ. Сравнивает два числа по битам и меняет специфические биты в числе.
Hızlı yanıt: kod örneği
The ^ operator in Java in Java is the exclusive-or ("xor") operator.Let's take as example:This the truth table for bitwise (JLS 15.22.1) and logical (JLS 15.22.2) xor:More simply, you can also think of xor as "this or that, but not both!".See also (casting the result to if necessary).You can also use the traditional bit-shifting trick to compute some powers of two. That is, is two to the k-th power for .See also to without using as a programming exercise ( denotes exponentiation from now on). The OP's intention was to compute ; the next part of this answer addresses that exponentiation is not necessary for this task.Horner's schemeAddressing your specific need, you actually don't need to compute various powers of 10. You can use what is called the Horner's scheme, which is not only simple but also efficient.Since you're doing this as a personal exercise, I won't give the Java code, but here's the main idea:It may look complicated at first, but it really isn't. You basically read the digits left to right, and you multiply your result so far by 10 before adding the next digit.In table form:
^
5^6
(decimal) (binary) 5 = 101 6 = 110------------------ xor 3 = 011
^ | 0 1 ^ | F T--+----- --+-----0 | 0 1 F | F T1 | 1 0 T | T F
- Wikipedia: exclusive-or
double Math.pow(double, double)
int
(1L << k)
k=0..63
- Wikipedia: Arithmetic shift
"8675309"
int
Integer.parseInt
^
8*10^6 + 6*10^5 + 7*10^4 + 5*10^3 + 3*10^2 + 0*10^1 + 9*10^0 = 8675309
8675309 = 8*10^6 + 6*10^5 + 7*10^4 + 5*10^3 + 3*10^2 + 0*10^1 + 9*10^0 = (((((8*10 + 6)*10 + 7)*10 + 5)*10 + 3)*10 + 0)*10 + 9
step result digit result*10+digit 1 init=0 8 8 2 8 6 86 3 86 7 867 4 867 5 8675 5 8675 3 86753 6 86753 0 867530 7 867530 9 8675309=final