开发者

Java IXOR ~ [one side] equality refactoring question

开发者 https://www.devze.com 2023-03-21 19:18 出处:网络
public byte[] method(int var1) { if(var1 == ~L.length) //<- this return a(i1, 0, false); } how would I go upon fixing
public byte[] method(int var1)
{
        if(var1 == ~L.length) //<- this
            return a(i1, 0, false);
}

how would I go upon fixing

if(var1 == ~L.length)

to remove the ~

must I change == to != ?

if(var1 != L.length)

Thanks this is probably the last question of this type.

ps.> Thanks for helping me out with the previous ones like

~(-1 + var1) < -1 to var1 > 1

~(var1 & 0x22) != -1 to (var1 & 0x22) != 0

~var1 < ~var2 to var1 &开发者_如何学Pythongt; var2


As I told you before, you can replace ~x with -x - 1

So, if(var1 == ~L.length) is equivalent to if(var1 == -L.length - 1)


If it's trying to do 2's complement tricks again:

-var1 == L.length + 1

or

var1 + 1 == -L.length

(Basically use the fact that ~x == -(x+1) == -x - 1)

Another way to rewrite it is:

var1 ^ L.length == -1
0

精彩评论

暂无评论...
验证码 换一张
取 消