hi
i have huge decimal elements in array. i want to convert it into 8 bit binary into another array.
I would appreciate any help!!!!
Thanks!!!
hi
i have huge decimal elements in array. i want to convert it into 8 bit binary into another array.
I would appreciate any help!!!!
Thanks!!!
What do you mean by "huge decimal elements"?
What do you mean by "8 bit binary"?
Give an example.
thanks for your comment.
for example...
in my "a" array, data are placed like [0 1 2 3.......... ]
I want to convert these array elements into 8 bit binary format('0'=00000000) in another array like [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1........]
thanks
It's still not entirely clear. What is the type of your "a" array? What about the other array?
Assuming it contains digit characters ('0', '1', etc.) and you want to convert them to unsigned chars of their respective values (0, 1, etc) :
Code:#include <stdio.h> void print_bits(unsigned char x) { unsigned char m = 0x80; for ( ; m; m >>= 1) putchar(x & m ? '1' : '0'); putchar('\n'); } int main() { char a[] = "0123"; unsigned char b[4]; for (size_t i = 0; i < 4; i++) b[i] = a[i] - '0'; for (size_t i = 0; i < 4; i++) print_bits(b[i]); return 0; }
thanks for quick response!!!
both are single dimensional array.
thanks
both array are integer types too.
thanks algorism!!!
I don't understand what you want.