File Parser for levels (#18)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Co-authored-by: Debucquoy Anthony (tonitch) <debucquoy.anthony@gmail.com> Reviewed-on: #18 Reviewed-by: Mat_02 <diletomatteo@gmail.com>
This commit is contained in:
43
app/src/main/java/school_project/Utils/Bitwise.java
Normal file
43
app/src/main/java/school_project/Utils/Bitwise.java
Normal file
@ -0,0 +1,43 @@
|
||||
package school_project.Utils;
|
||||
|
||||
import school_project.Vec2;
|
||||
|
||||
public class Bitwise {
|
||||
|
||||
/**
|
||||
* Check if the bit at pos is 1 or 0
|
||||
* @param b byte to test
|
||||
* @param pos position in b to check
|
||||
* @return true if the bit at pos is 1 or false if it is 0
|
||||
*/
|
||||
public static boolean IsBitSetAt(byte b, int pos){
|
||||
pos = 7 - pos;
|
||||
return (b & (1 << pos))!= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a byte (8 bit) to two Nible (4 bit) with a split in the middle
|
||||
* Exemple:
|
||||
* in = 01000101 (=69)
|
||||
* out = { 00000100, 00000101 } (={4, 5})
|
||||
*
|
||||
* @param in the byte to split
|
||||
* @return an arrya of 2 byte ret[0] = left part; ret[1] = right part
|
||||
*/
|
||||
public static Vec2 ByteToNible(byte in){
|
||||
Vec2 ret = new Vec2();
|
||||
ret.x = (byte) (in >> 4);
|
||||
ret.y = (byte) (in & 15); // apply the mask '00001111'
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform 2 byte into 1 with a left part ( 4 bits ) and a right part ( 4 bits)
|
||||
* @param left first 4 bits
|
||||
* @param right last 4 bits
|
||||
* @return concatenated byte
|
||||
*/
|
||||
public static byte NibbleToByte(byte left, byte right){
|
||||
return (byte) ((left << 4) | right);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user