K
K
koshiii2015-01-11 15:05:51
Java
koshiii, 2015-01-11 15:05:51

How to deal with bitwise operations in Java?

int a = 0xFF0;
int b = 0xF0F;
int c = 0x0FF;
c = a = (a^b | a & b)^c;
System.out.println((c | a) ^ (c & a));
==
Gives a result of 0
, write me a step-by-step solution plan
as you would decide on paper, otherwise nothing is clear no matter how hard you try , in theory you need to translate from 16 to 2, but it should be a simpler way for
a wildly long time . I ask for your help

Answer the question

In order to leave comments, you need to log in

6 answer(s)
P
Pavel, 2015-01-11
@mrusklon

use >>> or <<< ?

M
Max, 2015-01-11
@mbelskiy

"I'm lazy and don't want to do anything. Do it for me." So you won't get anywhere.
Convert from 16 -> 2 just a couple of seconds or banned in Google? And there, google the principle of operation and the priority of logical operations should not be a problem

D
Developer, 2015-01-11
@samodum

16 -> 2
This is a right shift of 3 bits, the fastest operation ever

A
anyd3v, 2015-01-11
@anyd3v

"in theory, it is necessary to translate from 16 to 2, but it's wildly long"
any sane calculator will do it for you within a couple of milliseconds

M
Maxim Moseychuk, 2015-01-12
@fshp

in theory, it is necessary to translate from 16 to 2, but this is wildly long

0xFF0 = similar numbers are translated simply - F is 1111.
0xFF0 == 111111110000

N
Nikolai Pavlov, 2015-01-12
@gurinderu

There is no need to convert anything here, here you need to look at the boolean logic.
Namely, on (c | a) ^ (c & a) . If c=a, this expression always gives 0. Since if c=a=1 then the left will be 1 and the right will be 1, then the xor operation will return 0. For 0, the left and right will be 0, xor is also 0)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question