summaryrefslogtreecommitdiff
path: root/c,cc/bitwise.c
diff options
context:
space:
mode:
Diffstat (limited to 'c,cc/bitwise.c')
-rw-r--r--c,cc/bitwise.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/c,cc/bitwise.c b/c,cc/bitwise.c
new file mode 100644
index 0000000..c90bfbd
--- /dev/null
+++ b/c,cc/bitwise.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+
+
+void
+test1()
+{
+ int foo[4] = {147, 142, 207, 19};
+ unsigned long result = 0;
+
+ for( int i = 0; i < 4; i += 1 )
+ {
+ result = result<<8; // 8 bit left
+ result = foo[i]|result;
+ }
+
+ printf("%lx\n", result);
+}
+
+void
+test2(void)
+{
+ int foo[4];
+ unsigned long bar = 0x938ecf13;
+
+ for( int i = 0; i < 4; i += 1 )
+ {
+ foo[i] = (bar>>i*8)&255;
+
+ printf("%d\n", foo[i]);
+ }
+}
+
+void
+test3(void)
+{
+ int s = 12;
+ unsigned long foo = 0xffffffff;
+
+ foo = foo<<s;
+ printf("%lx\n", foo);
+}
+
+int main(void)
+{
+ test1();
+ test2();
+ test3();
+
+ return 0;
+}
+