有人可以幫助我理解此代碼正在發生什麼。它看起來像是從一個數組中創建一個整數。我不知道它是如何做到這一點。爲什麼在OxFF上有一個按位操作&? Inst這會產生相同的結果?C位操作問題
//first take the first 4 bytes read out of the socket into an array and
//make them a 32 bit integer
long ltemp =0;
long ltemp2 = 0;
ltemp = ltemp | (unsigned char)(analog_val_ptr[0] & 0xff);
ltemp = ltemp << 24;
ltemp2 = ltemp2 | (unsigned char)(analog_val_ptr[1] & 0xff);
ltemp2 = ltemp2 << 16;
ltemp = ltemp2 | ltemp;
ltemp2 =0;
ltemp2 = ltemp2 | (unsigned char)(analog_val_ptr[2] & 0xff);
ltemp2 = ltemp2 << 8;
ltemp = ltemp2 | ltemp;
ltemp = ltemp | (unsigned char)(analog_val_ptr[3] & 0xff);
///then convert that integer into a float, passing
analog_val_ptr的類型是什麼?它看起來像程序員試圖通過使用'&0xFF'並轉換爲'unsigned char'來加倍確定。我想它們都可以自己做。 – john
它的一個字節,數據從套接字進入 – user489041