Reading binary file size in bytes and assigning it to uint16_t
Hi All,
In below piece of code, I am trying to read the size of a binary file in bytes and assign it to a variable of type uint16_t.
Code:
uint16_t readSize;
qDebug()<<"size of a binary file "<<fileName<< "is in bytes"<<f.size ()<<"\n"; ===> 131071 (expected value)
readSize = f.size ();
qDebug()<<"size of a binary file "<<readSize<<"\n";====> 65535 (Incorrect value)
/* updating file size to a struct variable of type uint16_t
req.Size = f.size ();====> 65535 (Incorrect value)
When I change readSize data type from int then
Code:
readSize = f.size ();
qDebug()<<"size of a binary file "<<readSize<<"\n";====> 131071
Is this because of data type uint16_t restricting? or size of the file exceeding the range of uint16_t?
Re: Reading binary file size in bytes and assigning it to uint16_t
Quote:
Originally Posted by
anita.niharika@gmail.com
Is this because of data type uint16_t restricting?
Yes - you can't represent 131071 with only 16bits.