Created
September 1, 2016 04:22
-
-
Save kinow/0edb3bebfe0d8e3386dd83481dc48b76 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 static void main(String[] args) { | |
int accumulator = 0; | |
byte b = 0; | |
int nbBitsUsed = 100; | |
/* classic version */ | |
while (nbBitsUsed >= 8) { /* each while test is a branch */ | |
accumulator <<= 8; | |
accumulator += b++; | |
nbBitsUsed -= 8; | |
} | |
System.out.println(accumulator); | |
System.out.println(b); | |
System.out.println(nbBitsUsed); | |
System.out.println(); | |
accumulator = 0; | |
b = 0; | |
nbBitsUsed = 100; | |
int nbBytesUsed = nbBitsUsed >> 3; | |
int ptr = 0; | |
nbBitsUsed &= 7; | |
ptr += nbBytesUsed; | |
accumulator = ptr; | |
System.out.println(accumulator); | |
System.out.println(b); | |
System.out.println(nbBitsUsed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment