From 9efcd0e6959b811cba85766285d9ad2520588248 Mon Sep 17 00:00:00 2001 From: Infendro Date: Thu, 24 Jul 2025 20:30:00 +0200 Subject: [PATCH] implement bitwise operations --- .../com/infendro/bytearray/operation.kt | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/commonMain/kotlin/com/infendro/bytearray/operation.kt diff --git a/src/commonMain/kotlin/com/infendro/bytearray/operation.kt b/src/commonMain/kotlin/com/infendro/bytearray/operation.kt new file mode 100644 index 0000000..0e0301f --- /dev/null +++ b/src/commonMain/kotlin/com/infendro/bytearray/operation.kt @@ -0,0 +1,35 @@ +package com.infendro.bytearray + +import kotlin.experimental.and +import kotlin.experimental.or +import kotlin.experimental.xor + +infix fun ByteArray.and( + that: ByteArray, +): ByteArray { + if (this.size != that.size) throw Exception() + + return ByteArray(size) { i -> + this[i] and that[i] + } +} + +infix fun ByteArray.or( + that: ByteArray, +): ByteArray { + if (this.size != that.size) throw Exception() + + return ByteArray(size) { i -> + this[i] or that[i] + } +} + +infix fun ByteArray.xor( + that: ByteArray, +): ByteArray { + if (this.size != that.size) throw Exception() + + return ByteArray(size) { i -> + this[i] xor that[i] + } +}