Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert C language into character type and assign it to character array?
How to convert C language into character type and assign it to character array?
A= 12345678 is an int type, which occupies 4 bytes in the memory and has * * 32 bits, namely 0000001010001/kloc-0.

Move A right by 24 bits, that is, take out the first 8 bits, that is, the first byte;

Move A to the right by 16, and then use 0000000111111.

If A is shifted to the right by 8 bits, it can be taken out that this bit is associated with 000000000000011111/kloc-0.

Combine bit A with 0000000000000000000000000011111,that is, 0xff can be taken out.

# include & ltstdio.h & gt

int main(void)

{

int a = 120;

char b[4];

b[0]= a & gt; & gt24;

b[ 1]=((a & gt; & gt 16); 0x ff);

b[2]=((a & gt; & gt8)& amp; 0x ff);

b[3]= a & amp; 0xff

Returns 0;

}