的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