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?
