Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Determines if a number is a power of two
- .class public Power
- .super java/lang/Object
- .method public <init>()V
- aload_0
- invokespecial java/lang/Object/<init>()V
- return
- .end method
- .method public static main([Ljava/lang/String;)V
- .limit stack 2
- getstatic java/lang/System.out Ljava/io/PrintStream ; Load a PrintStream onto the stack
- ldc 256 ; The number to check
- invokestatic Power/isPowerOfTwo(I)I ; Check the number
- invokevirtual java/io/PrintStream/println(I)V ; Output the result (0 = its a power of two)
- return
- .end method
- .method public static isPowerOfTwo(I)I
- .limit stack 2
- .limit locals 1
- iload_0 ; load the argument
- ldc 1 ; put "1" on the stack
- isub ; subtract arg-1
- iload_0 ; load the argument again
- iand ; bitwise and
- ireturn ; return the result
- .end method
Add Comment
Please, Sign In to add comment