2020-10-31 12:47:08 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2020-10-31 15:40:43 +01:00
|
|
|
void zeroth_bit_test();
|
|
|
|
|
|
|
|
unsigned char PTAD;
|
|
|
|
|
2020-10-31 12:49:18 +01:00
|
|
|
void do_bit_ops() {
|
2020-10-31 15:40:43 +01:00
|
|
|
PTAD = 0x10;
|
2020-10-31 14:33:35 +01:00
|
|
|
printf("PTAD = %#x\n* OR\n", PTAD);
|
2020-10-31 12:49:18 +01:00
|
|
|
PTAD |= 0x01;
|
2020-10-31 14:33:35 +01:00
|
|
|
printf("PTAD |= 0x01 --> %#010x (%#x)\n", PTAD, PTAD);
|
|
|
|
|
|
|
|
printf("----------\n* AND\n");
|
|
|
|
printf("PTAD = %#x\n", PTAD=0x1f);
|
2020-10-31 12:49:18 +01:00
|
|
|
PTAD &= 0xfe;
|
2020-10-31 14:33:35 +01:00
|
|
|
printf("PTAD &= 0xfe --> %#010x (%#x)\n", PTAD, PTAD);
|
|
|
|
|
|
|
|
printf("----------\n* NOT\n");
|
|
|
|
printf("PTAD = %#x\n", PTAD=0x10);
|
|
|
|
PTAD = ~PTAD;
|
|
|
|
printf("PTAD = ~PTAD --> %#010x (%#x)\n", PTAD, PTAD);
|
|
|
|
|
|
|
|
printf("----------\n* XOR\n");
|
|
|
|
printf("PTAD = %#x\n", PTAD=0x10);
|
|
|
|
PTAD ^= 0xfe;
|
|
|
|
printf("PTAD ^= 0xfe --> %#010x (%#x)\n", PTAD, PTAD);
|
2020-10-31 15:40:43 +01:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2020-10-31 12:49:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-31 12:47:08 +01:00
|
|
|
int main() {
|
|
|
|
printf("*** bit-ops pls ***\n");
|
2020-10-31 12:49:18 +01:00
|
|
|
do_bit_ops();
|
2020-10-31 12:47:08 +01:00
|
|
|
return 0;
|
|
|
|
}
|