At Monday 10/22/2007 01:51 AM, you wrote:
>--- In [email protected], Sanil P S <[EMAIL PROTECTED]> wrote:
> >
> > atoi will not work here.
> >
> > atoi just converts the string to integer.
> > ie; 4 bytes string like "1234" = 1234
> >
> > check the ASCII values for 1, 2 ,3 and 4
> > whcih are 49,50,51,52 corresponding hex values
> > are 31,32,22,34
> >
> > Binary representation of this is
> >
> > 0011 0001 0011 0010 0011 0011 0011 0100 ==>Hex
> > 31 32 33 34 ==> decimal 825373492
> >
> > I want to get
> >
> > Binary ===> Hex ===> decimal
> >
> > 00000001 00000001 0000001 00010000 ==>01 01 01 10
> > ==>16843024
> >
> > 00000001 00000001 0000001 00011110 ==>01 01 01 1E
> > ==>16843038
><snip>
>
>In this case it does make sense to read() (or recv(), for that matter)
>the four bytes as char*; however, processing goes on like this:
> /* Check that four bytes can be read: */
> if (read( ifd, chararr, sizeof( chararr)) != 4)
> { perror( "Couldn't read 4 length bytes");
> exit( EXIT_FAILURE);
> }
> /* else */
> /* Concatenate them into one long value: */
> longvalue = ( ( (unsigned long) (chararr [0])) << 24) +
> ( ( (unsigned long) (chararr [1])) << 16) +
> ( ( (unsigned long) (chararr [1])) << 8) +
> ( (unsigned long) (chararr [1]));
>
>[I know this is far too lengthy, but what the heck; it works, and
>that's the most important thing to me. Also the compiler doesn't care
>about the superfluous extra parentheses, so why should I; for me they
>help to make things clearer and safer, so I use them.]
>
>Regards,
>Nico
If the first 4 bytes are binary, and the remaining bytes are
character, you may need to setup a UNION
union /* Defines an array named data */
{
struct
{
unsigned int value;
char str[508];
} window1;
char inpline[512];
} data;
~Rick
>To unsubscribe, send a blank message to
><mailto:[EMAIL PROTECTED]>.
>Yahoo! Groups Links
>
>
>
[Non-text portions of this message have been removed]