-
Type Conversions
Im pulling in data through a winsock. The data im pulling in in of type Unsigned Char , Ive see an example that uses the following to displayed the data correctly
Code:
printf("Flags=%d\n",htons(pTcpheader->Flags));
Is there any other way to do this, possibly using cout? I also want to convert the data, and then compare it in a switch. Any ways to convert it besides that printf() would be appricated. Thanks.
-
The conversion is being done by htons, not by printf, so:
Code:
short value = htons(pTcpheader->Flags);
cout << "Flags = " << value;
switch (value) {
// do whatever ...
}
-
If it's only unsigned char then you don't need htons(). You only need to worry about endianness when the data is more than 1 byte.