的dataFile.bin是具有6个字节记录的二进制文件。第3个 字节每条记录都包含纬度和最后3个字节包含 经度。每24位值表示弧度乘以 0X1FFFFF转换为32位整数24位整数(2S补码)在C++
这是我一直在工作的任务。我还没有做过C++中的年,所以它把我方式的时间比我想象的还要-_-。围绕谷歌搜索后,我看到这个algorthim这对我有意义。
int interpret24bitAsInt32(byte[] byteArray) {
int newInt = (
((0xFF & byteArray[0]) << 16) |
((0xFF & byteArray[1]) << 8) |
(0xFF & byteArray[2])
);
if ((newInt & 0x00800000) > 0) {
newInt |= 0xFF000000;
} else {
newInt &= 0x00FFFFFF;
}
return newInt;
}
的问题是语法问题我限制被其他家伙编程这种方式工作。我不了解如何将CHAR“数据”存储到INT中。如果“数据”是一个数组,它会更有意义吗?由于它接收24个存储在BYTE中的信息整数。
double BinaryFile::from24bitToDouble(char *data) {
int32_t iValue;
// ****************************
// Start code implementation
// Task: Fill iValue with the 24bit integer located at data.
// The first byte is the LSB.
// ****************************
//iValue +=
// ****************************
// End code implementation
// ****************************
return static_cast<double>(iValue)/FACTOR;
}
bool BinaryFile::readNext(DataRecord &record)
{
const size_t RECORD_SIZE = 6;
char buffer[RECORD_SIZE];
m_ifs.read(buffer,RECORD_SIZE);
if (m_ifs) {
record.latitude = toDegrees(from24bitToDouble(&buffer[0]));
record.longitude = toDegrees(from24bitToDouble(&buffer[3]));
return true;
}
return false;
}
double BinaryFile::toDegrees(double radians) const
{
static const double PI = 3.1415926535897932384626433832795;
return radians * 180.0/PI;
}
我明白任何帮助,甚至如果你不理解的线索或提示将帮助我很多提示。我只需要与某人交谈。
@SergeyA哎呀,我确实复制粘贴超过了必要的。谢谢! – dasblinkenlight