• 07-27-2002
Unregistered
hello all.

i have this problem. i have a file that is full of numbers, i want
to take these numbers (two at a time) and treat them as

for example, a file that contains the numbers

534545245237

i want to make that :

0x53 0x45 0x45 0x24 0x52 0x37

and i want to check the bits of them one by one :

0x53 : 01010011 // ((if bit0==1){dothat();} if(bit2==0){donot();}

etc...

is there a way?

thanks a lot.
• 07-27-2002
simly01
There is a way
hi U,

What u can do is following

-- Create and array of some size,
-- open the file and read two char or int at a time
-- then add 0x to the front
-- story it into the array....

Thanks
• 07-27-2002
ygfperson
read through one character at a time. the ones column will be added to the other column times 16. ie:
54 = 4 + (5 * 16)
more technically
54 = (4 * 16^0) + (5 * 16^1)

by now you should have a hex number you want to test for bits. 1 looks like this:
Code:

`0000 0001`
if you want to test the ones digit here you want to mask away all the unnecessary digits. 0x54 looks like this:
Code:

`0101 0100`
to test a bit you want to logical and it. in c, it's this sign: &
Code:

```0101 0100 & 0000 0001 = 0000 0000```
and returns a one only when both are ones.
you want to set up this kind of loop:
Code:

```int x = 0x57; for (int i=0x80;i;i>>=1)   if (x & i)     printf("1");   else     printf("0");```
the i>>=1 shifts i's bit once to the right.
i starts off as
Code:

```1000 0000 0100 0000 0010 0000 0001 0000 0000 1000 0000 0100 0000 0010 0000 0001```
every time you test the other number to see if the bit is set, then do something accordingly.
• 07-27-2002
simly01
Nice
• 07-29-2002
Unregistered
hello and thanks for the answers,

ygfperson, in order to make the characters numbers, i must
use the atoi function. but what will happen if i have letters?
e.g. 0x5a?

thanks.