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
Ducktype
Bucles: terna pitagórica
Bucles: Triángulo de asteriscos lateral izquierdo
Numero pi Euler
Herout (67) - 4
Herout (67) - 12
Vectores: Dos vectores rellenos al azar
Triples bucles anidados
MyBlockQuicksort
lab7