Tag: uint16

C UINT16如何搞定?

我是C编程的新手,我正在测试一些代码,我收到并处理格式化如下的UDP数据包: UINT16 port1 UINT16 port2 此测试的相应值为: 6005 5555 如果我打印整个数据包缓冲区,我得到这样的东西: u^W³^U>^D 所以我认为我只需要打破它并处理为16字节的unsigned int 。 所以我尝试过这样的事情: int l = 0; unsigned int *primaryPort = *(unsigned int) &buffer[l]; AddToLog(logInfo, “PrimaryPort: %u\n”, primaryPort); l += sizeof(primaryPort); unsigned int *secondaryPort = *(unsigned int) &buffer[l]; AddToLog(logInfo, “SecondaryPort: %u\n”, secondaryPort); l += sizeof(secondaryPort); 但我得到8位数的错误数字。 我甚至尝试了另一种方法,如跟随,但也得到错误的数字。 int l = 0; unsigned char primaryPort[16]; […]