54 lines
1.1 KiB
C
54 lines
1.1 KiB
C
#include <stdio.h>
|
|
|
|
void zeroth_bit_test();
|
|
|
|
unsigned char PTAD;
|
|
|
|
void do_bit_ops() {
|
|
PTAD = 0x10;
|
|
printf("PTAD = %#x\n* OR\n", PTAD);
|
|
PTAD |= 0x01;
|
|
printf("PTAD |= 0x01 --> %#010x (%#x)\n", PTAD, PTAD);
|
|
|
|
printf("----------\n* AND\n");
|
|
printf("PTAD = %#x\n", PTAD=0x1f);
|
|
PTAD &= 0xfe;
|
|
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);
|
|
|
|
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");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
int main() {
|
|
printf("*** bit-ops pls ***\n");
|
|
do_bit_ops();
|
|
return 0;
|
|
}
|