From 540f65e3e77ca9a741392389d309d84cf64bebcf Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 31 Oct 2020 19:47:47 +0100 Subject: [PATCH] chore: add arbitrary stuff --- bit-ops.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/bit-ops.c b/bit-ops.c index bd44fe5..03e7b97 100644 --- a/bit-ops.c +++ b/bit-ops.c @@ -1,6 +1,7 @@ #include void zeroth_bit_test(); +void do_arbitrary_stuff(); unsigned char PTAD; @@ -26,6 +27,7 @@ void do_bit_ops() { printf("PTAD ^= 0xfe --> %#010x (%#x)\n", PTAD, PTAD); zeroth_bit_test(); + do_arbitrary_stuff(); } void zeroth_bit_test() { @@ -45,6 +47,37 @@ void zeroth_bit_test() { } } +void gimme_bin_int(char byte) { + for (int i = 0; i < 8; i++) { + printf("%d", !!((byte << i) & 0x80)); + } + printf(")\n"); +} + +void do_arbitrary_stuff() { + unsigned char PTCD; + /* set 1st bit to 1 */ + printf("----------\n* set 1st bit to 1\n"); + printf("PTCD = %#x\n", PTCD=0x00); + PTCD |= 0x01; + printf("PTCD |= 0x01 --> %#010x (", PTCD); + gimme_bin_int(PTCD); + + printf("----------\n* set 2nd bit to 1\n"); + printf("PTCD = %u (", PTCD=0b101); + gimme_bin_int(PTCD); + PTCD |= 0b111; + printf("PTCD |= 7 --> %#010x (", PTCD); + gimme_bin_int(PTCD); + + printf("----------\n* set {6,7}th bit to 1\n"); + printf("PTCD = %u (", PTCD=0x3a); + gimme_bin_int(PTCD); + PTCD |= 0xc0; + printf("PTCD |= 1110 0000 --> %#010x (", PTCD); + gimme_bin_int(PTCD); +} + int main() { printf("*** bit-ops pls ***\n");