Mit einem Makro.
#include <stdio.h>
#define BIN8(num) bin8(num)
#define BIN16(num) bin16(num)
#define UBIN16(num) ubin16(num)
// Makro zur Umwandlung in 8-Bit-Binärformat für signed und unsigned
#define bin8(num) \
(num & 0b10000000 ? '1' : '0'), \
(num & 0b01000000 ? '1' : '0'), \
(num & 0b00100000 ? '1' : '0'), \
(num & 0b00010000 ? '1' : '0'), \
(num & 0b00001000 ? '1' : '0'), \
(num & 0b00000100 ? '1' : '0'), \
(num & 0b00000010 ? '1' : '0'), \
(num & 0b00000001 ? '1' : '0')
// Makro zur Umwandlung in 16-Bit-Binärformat für signed Ganzzahlen
#define bin16(num) \
((num & 0x8000) ? '1' : '0'), \
((num & 0x4000) ? '1' : '0'), \
((num & 0x2000) ? '1' : '0'), \
((num & 0x1000) ? '1' : '0'), \
((num & 0x0800) ? '1' : '0'), \
((num & 0x0400) ? '1' : '0'), \
((num & 0x0200) ? '1' : '0'), \
((num & 0x0100) ? '1' : '0'), \
((num & 0x0080) ? '1' : '0'), \
((num & 0x0040) ? '1' : '0'), \
((num & 0x0020) ? '1' : '0'), \
((num & 0x0010) ? '1' : '0'), \
((num & 0x0008) ? '1' : '0'), \
((num & 0x0004) ? '1' : '0'), \
((num & 0x0002) ? '1' : '0'), \
((num & 0x0001) ? '1' : '0')
// Makro zur Umwandlung in 16-Bit-Binärformat für unsigned Ganzzahlen
#define ubin16(num) \
(num & 0b1000000000000000 ? '1' : '0'), \
(num & 0b0100000000000000 ? '1' : '0'), \
(num & 0b0010000000000000 ? '1' : '0'), \
(num & 0b0001000000000000 ? '1' : '0'), \
(num & 0b0000100000000000 ? '1' : '0'), \
(num & 0b0000010000000000 ? '1' : '0'), \
(num & 0b0000001000000000 ? '1' : '0'), \
(num & 0b0000000100000000 ? '1' : '0'), \
(num & 0b0000000010000000 ? '1' : '0'), \
(num & 0b0000000001000000 ? '1' : '0'), \
(num & 0b0000000000100000 ? '1' : '0'), \
(num & 0b0000000000010000 ? '1' : '0'), \
(num & 0b0000000000001000 ? '1' : '0'), \
(num & 0b0000000000000100 ? '1' : '0'), \
(num & 0b0000000000000010 ? '1' : '0'), \
(num & 0b0000000000000001 ? '1' : '0')
int main() {
int i = 6;
signed int si = -6;
short s = 6;
short us = -6;
printf("Unsigned 8 Bit: %c%c%c%c %c%c%c%c\n", bin8(i));
printf("Signed 8 Bit: %c%c%c%c %c%c%c%c\n", bin8(si));
printf("Unsigned 16 Bit: %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c\n", ubin16(us));
printf("Signed 16 Bit: %c%c%c%c %c%c%c%c %c%c%c%c %c%c%c%c\n", bin16(s));
return 0;
}