Je n'arrive pas à comprendre les octets hexadécimaux. Lorsqu'un manuel indique l'identifiant d'en-tête en hex-ascii comme 7Fh, cela signifie 0111 1111 à droite? Ce qui convertit à 127 en décimal selon les convertisseurs hexadécimaux en ligne.Impossible de convertir Hex en Decimal correctement
string dataString;
//cout << dataString << endl;
//the output of dataString starts with "7F0304"
struct SENSOR_O
{
fLeader fixedLeader;
vLeader varLeader;
vel velocity;
pos position;
bTrack bottomTrack;
bool error;
std::string error_msg;
};
SENSOR_O datafields;
datafields = ParseData(dataString)
my class::SENSOR_O myclass::ParseData(const std::string &data)
{
const unsigned char *memblock;
ifstream::pos_type size;
ifstream test;
vector<double> dataSum;
int headerID = 125;
int startID = 0;
memblock = reinterpret_cast<const unsigned char *>(data.data());
cout << data[0] << data[1] << data[2] << data[3] << endl;
cout << "check value: "<< memblock[startID] << ", " << memblock[startID+1]<< endl;
cout << "double check value: " << double(memblock[startID]) << ", " << double(memblock[startID+1]) << endl;
cout << "7F should give me 127. Yes? Added total is: " << double(memblock[startID]) + double(memblock[startID+1]) << ends;
}
La sortie que je vois est
7F03
7, F
55, 70
7F should give me 127. Yes? Added total is: 125
Qu'ai-je fait de mal ici?
Pouvez-vous s'il vous plaît montrer le reste du code pertinent? – xunatai
Cela devrait être suffisant, s'il vous plaît laissez-moi savoir si vous avez besoin de quelque chose d'autre :) –