Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In C language, two bytes are converted into a signed short integer.
In C language, two bytes are converted into a signed short integer.
32-bit machine, you can look at the following program, I wrote it myself.

# include & ltstdio.h & gt

# include & ltstring.h & gt

//Determine whether your computer is large or small.

int is_little(){

Joint test {

int num

Character string;

} t;

t . num = 1;

return t . str = = 1;

}

int main(){

Char* str= "Your string"; //Your string

Short tmp [100]; //Your array

int I;

for(I = 0; I< strlen (str)/2; i++){

if(is_little()){

/* The small end must be adjusted manually.

Can be replaced by

char a = *(str+I * 2);

char b = *(str+I * 2+ 1);

tmp[I]= a * 256+b;

*/

int org =(*(int *)(str+I * 2))& lt; & lt 16 >& gt 16;

int a = org & lt& lt24 >; & gt24;

int b = org & gt& gt8;

tmp[I]= a * 256+b;

} Otherwise {

tmp[I]= *(int *)(str+I * 2)& gt; & gt 16;

}

printf("%d ",tmp[I]);

}

printf(" \ n ");

Returns 0;

}