aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/BitManipulation.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/BitManipulation.kt')
-rw-r--r--src/main/kotlin/BitManipulation.kt27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/kotlin/BitManipulation.kt b/src/main/kotlin/BitManipulation.kt
new file mode 100644
index 0000000..a9f9493
--- /dev/null
+++ b/src/main/kotlin/BitManipulation.kt
@@ -0,0 +1,27 @@
+object BitManipulation {
+
+ fun bytesToWord(msb: Int, lsb: Int): Int {
+ return msb.shl(8) + lsb
+ }
+
+ fun getMsb(value: Int): Int {
+ return value.shr(8)
+ }
+
+ fun getLsb(value: Int): Int {
+ return value.and(0xFF)
+ }
+
+ fun validateUnsigned8Bit(value: Int) {
+ if(value < 0 || value > 255) {
+ throw IllegalArgumentException("Value $value is not an unsigned 8-Bit value")
+ }
+ }
+
+ fun validateUnsigned16Bit(value: Int) {
+ if(value < 0 || value > 65535) {
+ throw IllegalArgumentException("Value $value is not an unsigned 16-Bit value")
+ }
+ }
+
+} \ No newline at end of file