summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-03-23 16:18:38 -0400
committerpommicket <pommicket@gmail.com>2023-03-23 16:18:38 -0400
commitaf61b9be6a746421a0417d282134491213f2c03f (patch)
treeb81b5fe297cc2d4f029ec111b9ac6a9228b1c4f8 /util.c
parent6643ff4c14cc27bf80189aadaf65c36ac2e7307f (diff)
handle various :increment-number edge cases and binary
Diffstat (limited to 'util.c')
-rw-r--r--util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/util.c b/util.c
index 38d201a..f441479 100644
--- a/util.c
+++ b/util.c
@@ -258,6 +258,28 @@ char *a_sprintf(const char *fmt, ...) {
return str;
}
+void str_binary_number(char s[65], u64 n) {
+ if (n == 0) {
+ strcpy(s, "0");
+ return;
+ }
+
+ u64 digits = 0;
+ u64 m = n;
+ while (m) {
+ m >>= 1;
+ digits += 1;
+ }
+
+ m = n;
+ s[digits] = '\0';
+ char *p = s + digits - 1;
+ while (m) {
+ *p-- = (m & 1) + '0';
+ m >>= 1;
+ }
+}
+
// advances str to the start of the next UTF8 character
static void utf8_next_char_const(const char **str) {