From bcf29a697fcdec5dd6c9aae43d434bff147942f0 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 31 Oct 2020 15:40:43 +0100 Subject: [PATCH] chore: add 0th bit test --- bit-ops.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bit-ops.c b/bit-ops.c index d671d6e..bd44fe5 100644 --- a/bit-ops.c +++ b/bit-ops.c @@ -1,7 +1,11 @@ #include +void zeroth_bit_test(); + +unsigned char PTAD; + void do_bit_ops() { - unsigned char PTAD = 0x10; + PTAD = 0x10; printf("PTAD = %#x\n* OR\n", PTAD); PTAD |= 0x01; printf("PTAD |= 0x01 --> %#010x (%#x)\n", PTAD, PTAD); @@ -20,6 +24,25 @@ void do_bit_ops() { printf("PTAD = %#x\n", PTAD=0x10); PTAD ^= 0xfe; printf("PTAD ^= 0xfe --> %#010x (%#x)\n", PTAD, PTAD); + + zeroth_bit_test(); +} + +void zeroth_bit_test() { + PTAD = 0x10; + printf("----------\n* 0th bit test\n"); + for (PTAD = 0x00; PTAD < 0x0a; PTAD++){ + printf("PTAD = %u (", PTAD); + for (int i = 0; i < 8; i++) { + printf("%d", !!((PTAD << i) & 0x80)); + } + printf(")\n"); + if ( PTAD & 0x01 ) { + printf("0th bit is 1\n"); + } else { + printf("0th bit is 0\n"); + } + } }