This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <limits.h> | |
| #include <stdint.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| /* Implementações de ImprimeBitsGenerico e little_endian omitidas aqui */ | |
| int main(void) | |
| { | |
| int x, bits_por_linha, bits_por_bloco; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ImprimeBitsGenerico(const void *p, size_t tam, | |
| size_t bits_por_bloco, size_t bits_por_linha) | |
| { | |
| unsigned char mascara; | |
| const char *blocos; | |
| int i, j, bits_impressos; | |
| int ini, fim, incr; | |
| blocos = (char *)p; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ImprimeBitsGenerico(const void *p, size_t tam) | |
| { | |
| char c; | |
| unsigned char mascara; | |
| const char *blocos; | |
| int i, j, little; | |
| int ini, fim, incr; | |
| blocos = (char *)p; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int little_endian(void) | |
| { | |
| uint16_t n = 1; | |
| return 1 == *(uint8_t *) &n; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <limits.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| /* Implementação de ImprimeBits e ImprimeBitsGenerico omitida aqui */ | |
| int main(void) | |
| { | |
| int x = 10; | |
| ImprimeBits(x); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ImprimeBitsGenerico(const void *p, size_t tam) | |
| { | |
| char c; | |
| unsigned char mascara; | |
| const char *blocos; | |
| int i, j; | |
| blocos = (char *)p; | |
| for (i = 0; i < tam; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ImprimeBits(int x) | |
| { | |
| char c; | |
| int i, nbits; | |
| unsigned mascara; | |
| nbits = CHAR_BIT * sizeof(x); | |
| mascara = 1 << (nbits - 1); | |
| for (i = 0; i < nbits; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define BITS_POR_BYTES 8 | |
| void ImprimeBits(int x) | |
| { | |
| char c; | |
| int i, nbits; | |
| unsigned mascara; | |
| nbits = BITS_POR_BYTES * sizeof(x); | |
| mascara = 1 << (nbits - 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <stdlib.h> | |
| /* Implementação de ImprimeBits omitida aqui */ | |
| int main(void) | |
| { | |
| int x = 10; | |
| ImprimeBits(x); | |
| return EXIT_SUCCESS; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void ImprimeBits(int x) | |
| { | |
| char c; | |
| int i, nbits; | |
| unsigned mascara; | |
| nbits = 32; | |
| mascara = 1 << (nbits - 1); | |
| for (i = 0; i < nbits; i++) { |