Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How c# Converts Byte Arrays into Integers
How c# Converts Byte Arrays into Integers
"//An array of bytes converted to an integer.

1) method 1

int j = 0;

j =(int)db[0]; //restore byte 1 (low order)

j+=(int)db[ 1]& lt; & lt8; //Recover the 2nd byte

j+=(int)db[2]& lt; & lt 16; //Recover the 3rd byte

j+=(int)db[3]& lt; & lt24; //Recover the 4th byte (high bit)

Console. WriteLine (""Restore to Integer by shift: {0} "",j);

2) Method 2

The Marshal class contains most methods of memory operation, such as space allocation, pointer, memory copy, memory reading and writing, etc. The following code uses Marshal to achieve the same function as above:

int I = 1234567; //The corresponding hexadecimal number is 00 12D687. "