Hi Leute, ich habe ein Problem, welches ich nicht bearbeiten konnte. Ich will 2 short Variablen in einen Int-Bereich packen (packing&unpacking): 2x2Bytes -> 4 Bytes. Ich habe folgendes probiert: short s1,s2; int temp; temp &= 0x0000; //clear bits fscanf(file,"%d",&s1); //read input1: temp = s1<<16; fscanf(file,"%d",&s2); //read input2: temp = temp | s2; Kann mir jemand sagen, was daran falsch ist?
> temp = s1<<16;
damit schiebst du das ergebnis aus dem short raus bevor es dem int
zugewiesen wird. probier mal folgendes:
temp = s1;
temp = temp << 16;
Es funktioniert jetzt: short s1,s2; int temp; temp &= 0x00000000; //clear bits fscanf(file,"%d",&s1); //read input1: fscanf(file,"%d",&s2); //read input2: temp = s1; temp = (temp<<16)&FFFF0000; temp |= s2; Danke!
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.