누군가이 코드를 어떻게 처리하는지 이해할 수 있습니까? 비트 배열에서 정수를 만드는 것처럼 보입니다. 어떻게 그 일을하는지 확실하지 않습니다. 0xFF에서 비트가 & 인 이유는 무엇입니까? 동일한 결과를 산출 할 예정입니까? 다만 32 비트 길이로 4 개의 8 비트 바이트를 변환하는 매우 장황한 방법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