Hello all.
I use to program in VB,but decided recently to try also C++.
I read the learning tutorial here which was very helpful.
My question is,how can I convert bytes values into integer.
I read a file using char[] and I want to convert specific bytes to integer.
For example,to convert the bytes from char[57] to char[60] into integer.
In VB there is a function bitconverter.ToInt32(array() as byte,start_pos as integer).
template <typename IntegerType>
IntegerType bitsToInt( IntegerType& result, constunsignedchar* bits, bool little_endian = true )
{
result = 0;
if (little_endian)
for (int n = sizeof( result ); n >= 0; n--)
result = (result << 8) +bits[ n ];
elsefor (unsigned n = 0; n < sizeof( result ); n++)
result = (result << 8) +bits[ n ];
return result;
}