Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bit string printer
// print bit string of inputted data #include <stdio.h> #include <stdlib.h> int endianness; void printBitStr(void *data, int size) { char *byteData = (char *)data; char *bitStr = (char *)malloc( (size * 8) + size); int sNum = 0; if(endianness) { // little endian? sNum = size-1; } int i, j; for(i=0; i<size; ++i) { for(j=0; j<8; ++j) { bitStr[ i*9 + j] = '0' + (byteData[sNum-i]>>(7-j)&1); } bitStr[ i*9 + j] = '|'; // byte spacer char } bitStr[size * 8 + size - 1] = '\0'; printf("%s\n", bitStr); free(bitStr); } int main(void) { // little / big endian switch. little = 1, big = 0 endianness = 1; endianness = *(char *)&endianness; int i = 10; printBitStr(&i, sizeof(int)); float j = 10.0; printBitStr(&j, sizeof(float)); return 0; }
run
|
edit
|
history
|
help
0
fun kce
Bucles: terna pitagórica
Lazy dope vectors by Henry Kroll III www.thenerdshow.com
Detecta vocales
Linear Classifier in C
0003
lab7
definice funkce
life
ternary test c89