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


I need some method or function to convert this 
string data into integer.


==================================================



--- Ananth <[EMAIL PROTECTED]> wrote:

> Sanil P S <[EMAIL PROTECTED]> wrote:
> >  I am reading some data from a socket( TCP/IP)
> >  I need to interprent the data by parsing.
> >  The first 4 bytes of this data repreent
> >  and integer.Next field is a string ending by
> >  a null character and So on.
> >
> >  I read the data from socket into a char*
> dynamically
> >  allocated.
> >
> >  I am looking for functions /logic to interprent
> the
> >  first four bytes into an integer.
> 
> Put your 4 (ASCII) bytes into a string, and then
> call string to
> integer conversion function, atoi
> 
> >  Please note that the fields are encoded binary
> style.
> >  ie; the biggest integer represented in four bytes
> is
> >  "FFFF" and NOT "9999".
> 
> Hexadecimal you mean? not binary.
> 
> 
> >  Thank you for the response.
> >
> >  --- Nico Heinze <[EMAIL PROTECTED]> wrote:
> >  > <[EMAIL PROTECTED]> wrote:
> >  > >
> >  > > Hi All,
> >  > >
> >  > > I am writing a parser for incoming packets
> >  > > of a protocol. The fields are interpreted
> >  > > binary. ie; 4 bytes for an int,character
> single
> >  > byte,
> >  > > string values/text
> >  > > values are parsed until end of string is
> reached
> >  > > and so on.
> >  > >
> >  > > I used a char* and allocated the incoming
> size
> >  > > dynamically, for receiving the incoming
> packet.
> >  > > Parsed the byte array using string methods.
> >  > > I tried using some byte array implementations
> >  > > like QByteArray of Qt. But it is working just
> >  > > like a string implementation. taking '\0'
> >  > > as end of the array.
> >  > >
> >  > > I need an implementation or method to parse
> the
> >  > > binary incoming packets and interpret them to
> >  > > values.
> >  > >
> >  > > Please help me with any suggestions. At least
> >  > > pointers to which byte array implementations
> I
> >  > should
> >  > > use or .. how to parse and interpret char*
> arrays
> >  > > in a binary way.
> >  >
> >  > The trouble with char* in your case is that
> it's
> >  > designed to work with
> >  > NUL terminated strings and nothing else. If you
> want
> >  > to use those
> >  > functions on something else, you will have to
> write
> >  > your own libraries
> >  > and/or functions. That's it.
> >  >
> >  > However, MY main problem is that I am not quite
> sure
> >  > that I really
> >  > understand what you mean. Could you please
> provide
> >  > some easy example?
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to