aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib/bytes.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-07-10 14:45:07 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-07-10 14:45:07 -0400
commit394da24c854fdd2dc08e37090263972b732f5424 (patch)
tree5fafbf0b64b0883d176418747b45b7d8316ca6c9 /src/stdlib/bytes.c
parent39501916acc08208360d9f920af425d0e8e230bb (diff)
parentcd1e9b5fd52dbc993463d58c41895aba9cd78966 (diff)
Merge branch 'main' into decimals
Diffstat (limited to 'src/stdlib/bytes.c')
-rw-r--r--src/stdlib/bytes.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c
index b5c10aa2..48c8b93b 100644
--- a/src/stdlib/bytes.c
+++ b/src/stdlib/bytes.c
@@ -49,6 +49,14 @@ public Text_t Byte$hex(Byte_t byte, bool uppercase, bool prefix) {
return text;
}
+public bool Byte$get_bit(Byte_t x, Int_t bit_index) {
+ if (Int$compare_value(bit_index, I(1)) < 0)
+ fail("Invalid bit index (expected 1 or higher): ", bit_index);
+ if (Int$compare_value(bit_index, I(8)) > 0)
+ fail("Bit index is too large! There are only 8 bits in a byte, but index is: ", bit_index);
+ return ((x & (Byte_t)(1L << (Int64$from_int(bit_index, true)-1L))) != 0);
+}
+
#ifdef __TINYC__
#define __builtin_add_overflow(x, y, result) ({ *(result) = (x) + (y); false; })
#endif