#include <stdio.h> #include <stdlib.h> #include <math.h> void BinFormat(char character, char *text) { text[8] = '\0'; for (int i = 7; i >= 0; i--) { int cabe = character / divisor; //acha quantas unidades cabem no divisor int impar = (cabe % 2 != 0); //o que cabe é impar? text[i] = impar + '0'; //transfoprma um número em caractere de acordo com a tabela ASCII } } int main(void) { BinFormat('A', text); BinFormat('B', text); BinFormat('C', text); } //https://pt.stackoverflow.com/q/286742/101
Standard input is empty
[128, 0, 0] [64, 1, 1] [32, 2, 0] [16, 4, 0] [8, 8, 0] [4, 16, 0] [2, 32, 0] [1, 65, 1] 10000010 [128, 0, 0] [64, 1, 1] [32, 2, 0] [16, 4, 0] [8, 8, 0] [4, 16, 0] [2, 33, 1] [1, 66, 0] 01000010 [128, 0, 0] [64, 1, 1] [32, 2, 0] [16, 4, 0] [8, 8, 0] [4, 16, 0] [2, 33, 1] [1, 67, 1] 11000010