diff options
Diffstat (limited to 'src/main/java/org/mamago/util')
| -rw-r--r-- | src/main/java/org/mamago/util/Bits.java | 16 | ||||
| -rw-r--r-- | src/main/java/org/mamago/util/Cast.java | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/org/mamago/util/Bits.java b/src/main/java/org/mamago/util/Bits.java new file mode 100644 index 0000000..4672ea9 --- /dev/null +++ b/src/main/java/org/mamago/util/Bits.java @@ -0,0 +1,16 @@ +package org.mamago.util; + +public class Bits { + // Prevent instantiation + private Bits() {} + + public static int roundUpToLongSize(int size) { + return roundUpToSize(size, 8); + } + + public static int roundUpToSize(int size, int width) { + // Formula: + // (size + w) / w * w; // Adding w rounds up to the next whole width + return ((size + width) / width) * width; + } +} diff --git a/src/main/java/org/mamago/util/Cast.java b/src/main/java/org/mamago/util/Cast.java new file mode 100644 index 0000000..4ed3d47 --- /dev/null +++ b/src/main/java/org/mamago/util/Cast.java @@ -0,0 +1,16 @@ +package org.mamago.util; + +public class Cast { + // Prevent instantiation + private Cast() {} + + public static byte asByte(int i) { + // @Fixme[MA]: check whether casting give out-of-bounds check, otherwise add in for safety + return (byte) i; + } + + public static short asShort(int i) { + // @Fixme[MA]: check whether casting give out-of-bounds check, otherwise add in for safety + return (byte) i; + } +} |
