Pregunta

On mac os x I have been using the NSSwap*ToHost family of functions for unsigned integers.

What is the correct way to do this for signed integers of size 8, 16, 32 and 64? I've seen the ntoh* functions recommended in other stack overflow posts but they return unsigned integers.

¿Fue útil?

Solución

You can use the same method for signed integers, just use some casting to quiet down the compiler.

Otros consejos

You should have no problem using these functions for signed endianess swapping if you cast the values to unsigned integers and back. However: if you want to explicitly convert little endian data to big endian data you should not use these functions since the ntoh* functions will perform no swapping on big endian architectures. On the other hand, if you just want to make sure data from your local machine is converted to big endian, regardless of your local machine's endianness, these functions will do just fine.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top