Hello!
How can i convert an integer-value into a char-field like the following?
Position: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 -------------------------------
----
Bit: 1 | 1 | 0 | 0 | 0 | 1 | 1 | 1 | \0
I try to convert the int-value in an string because i'd like to find out
which bits are set in this value.
In get informations per parallelport from an external device that send's
its different statusinfos in different bits in a byte. The first bit is on
or off. But how to recognize whether this bit is on or off?
I'am not so good in C but i try to write an program to control an device, i
developed some time ago. At now i use my windows-program which i've written
in VB. Now i'd like to control it with a linux-version of this program.
My Code till now:
// BEGIN
void bytetobin(unsigned int byte) {
long i;
int mask;
char bin[144];
mask=1;
for(i=0;i<=3;i++) {
if(byte!=0 && mask!=0)
bin[16-i*2]=49;
else
bin[16-i*2]=48;
mask=mask*2;
}
bin[8]=32;
for(i=4;i<=7;i++) {
if(byte!=0 && mask!=0)
bin[14-i*2]=49;
else
bin[14-i*2]=48;
mask=mask*2;
}
printf("value: %s\n",bin);
//ENDQuote:}
I've tried to convert my VB-function into a C-function. But it doesn't work
as expected.
Thanks, to all who spend a piece of their time on my problem.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/