Re: [Dev-C++] form binary data to unisgned int
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2006-03-23 12:58:19
|
If you are lazy, and the data is in correct byte order, then you can do: char readbuf[100]; unsigned int n; n = *(unsigned int*)&readbuf[pos]; However, to make sure that the program works independent on processor architecture, you should do something like: n = ((unsigned)buf[pos]) + (((unsigned)buf[pos+1]) << 8) + (((unsigned)buf[pos+2]) << 16) + (((unsigned)buf[pos+3]) << 24); pos += 4; Adjust order of bytes depending on how the file was saved. /Per W On Thu, 23 Mar 2006, Riccardo Roasio wrote: > Hi, > i have a file with a part of ASCII code and a second part with binary > data that should represent unsigned int. > I found how to read the file and write on another file the same binary > data, but i don't know how to convert these data into unsigned int. > Can anyone help me? > Thanks,Riccardo > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |