2 short Variablen in int packen

Gast #830899
Lesenswert?

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?
Gast #830929
Lesenswert?

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!

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren