Last active
June 20, 2018 19:59
-
-
Save LuxXx/ad614c285c7ad772b1f4d7fa5c515e71 to your computer and use it in GitHub Desktop.
isEven bit vs mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IsEven { | |
public static boolean isEven_bit(int i) { | |
return (i & 1) == 0; | |
} | |
public static boolean isEven_mod(int i) { | |
return i % 2 == 0; | |
} | |
public static void main(String[] args) { | |
isEven_bit(2); | |
isEven_mod(2); | |
} | |
} | |
public class IsEven | |
{ | |
public static boolean isEven_bit(int paramInt) { | |
return (paramInt & 0x1) == 0; | |
} | |
public static boolean isEven_mod(int paramInt) { return paramInt % 2 == 0; } | |
public static void main(String[] paramArrayOfString) { | |
isEven_bit(2); | |
isEven_mod(2); | |
} | |
} | |
public class IsEven { | |
<ClassVersion=52> | |
<SourceFile=IsEven.java> | |
public IsEven() { // <init> //()V | |
L1 { | |
aload0 // reference to self | |
invokespecial java/lang/Object.<init>()V | |
return | |
} | |
} | |
public static isEven_bit(int arg0) { //(I)Z | |
L1 { | |
iload0 | |
iconst_1 | |
iand | |
ifne L2 | |
iconst_1 | |
goto L3 | |
} | |
L2 { | |
f_new (Locals[1]: 1) (Stack[0]: null) | |
iconst_0 | |
} | |
L3 { | |
f_new (Locals[1]: 1) (Stack[1]: 1) | |
ireturn | |
} | |
} | |
public static isEven_mod(int arg0) { //(I)Z | |
L1 { | |
iload0 | |
iconst_2 | |
irem | |
ifne L2 | |
iconst_1 | |
goto L3 | |
} | |
L2 { | |
f_new (Locals[1]: 1) (Stack[0]: null) | |
iconst_0 | |
} | |
L3 { | |
f_new (Locals[1]: 1) (Stack[1]: 1) | |
ireturn | |
} | |
} | |
public static main(java.lang.String[] arg0) { //([Ljava/lang/String;)V | |
L1 { | |
iconst_2 | |
invokestatic IsEven.isEven_bit(I)Z | |
pop | |
} | |
L2 { | |
iconst_2 | |
invokestatic IsEven.isEven_mod(I)Z | |
pop | |
} | |
L3 { | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment