chore: add arbitrary stuff

This commit is contained in:
surtur 2020-10-31 19:47:47 +01:00
parent bcf29a697f
commit 540f65e3e7
Signed by: wanderer
GPG Key ID: 19CE1EC1D9E0486D

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
void zeroth_bit_test(); void zeroth_bit_test();
void do_arbitrary_stuff();
unsigned char PTAD; unsigned char PTAD;
@ -26,6 +27,7 @@ void do_bit_ops() {
printf("PTAD ^= 0xfe --> %#010x (%#x)\n", PTAD, PTAD); printf("PTAD ^= 0xfe --> %#010x (%#x)\n", PTAD, PTAD);
zeroth_bit_test(); zeroth_bit_test();
do_arbitrary_stuff();
} }
void zeroth_bit_test() { 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() { int main() {
printf("*** bit-ops pls ***\n"); printf("*** bit-ops pls ***\n");