summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/bitsets/bits2.c
diff options
context:
space:
mode:
author_Tradam <[email protected]>2023-09-08 01:29:47 +0000
committerGitHub <[email protected]>2023-09-08 01:29:47 +0000
commit3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch)
treeafbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/bitsets/bits2.c
parent0841165881871ee01b782129be681209aeed2423 (diff)
parent1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff)
downloadSTC-modified-modified.tar.gz
STC-modified-modified.zip
Merge branch 'stclib:master' into modifiedHEADmodified
Diffstat (limited to 'misc/examples/bitsets/bits2.c')
-rw-r--r--misc/examples/bitsets/bits2.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/misc/examples/bitsets/bits2.c b/misc/examples/bitsets/bits2.c
new file mode 100644
index 00000000..de2f16f4
--- /dev/null
+++ b/misc/examples/bitsets/bits2.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+// Example of static sized (stack allocated) bitsets
+
+#define i_type Bits
+#define i_capacity 80 // enable fixed bitset on the stack
+#include <stc/cbits.h>
+
+int main(void)
+{
+ Bits s1 = Bits_from("1110100110111");
+
+ printf("size %lld\n", Bits_size(&s1));
+ char buf[256];
+ Bits_to_str(&s1, buf, 0, 256);
+ printf("buf: %s: count=%lld\n", buf, Bits_count(&s1));
+
+ Bits_reset(&s1, 8);
+ printf(" s1: %s\n", Bits_to_str(&s1, buf, 0, 256));
+
+ Bits s2 = Bits_clone(s1);
+
+ Bits_flip_all(&s2);
+ Bits_reset(&s2, 66);
+ Bits_reset(&s2, 67);
+ printf(" s2: ");
+ c_forrange (i, Bits_size(&s2))
+ printf("%d", Bits_test(&s2, i));
+ puts("");
+
+ printf("xor: ");
+ Bits_xor(&s1, &s2);
+ c_forrange (i, Bits_size(&s1))
+ printf("%d", Bits_test(&s1, i));
+ puts("");
+
+ printf("all: ");
+ Bits_set_pattern(&s1, 0x3333333333333333);
+ c_forrange (i, Bits_size(&s1))
+ printf("%d", Bits_test(&s1, i));
+ puts("");
+}