I have to use the two functions to convert the transmission data between client and server, the problem is that the data buffer must necessarily be uint8_t but ntohs and htons want uint16_t otherwise they don't work; so I have to bring the data into uint16_t and convert it back to uint8_t. but the data converted and brought to uint8_t are null, that is '0'. where am i wrong?
Asked
Active
Viewed 372 times
0

the busybee
- 10,755
- 3
- 13
- 30

Bob02
- 1
-
8`uint8_t` is a single byte. Endianess doesn't apply to a single byte. – Thomas Jager Jun 19 '20 at 21:38
-
okay, the thing is, i can't use 2 bytes per character. how can I do? – Bob02 Jun 19 '20 at 21:56
-
sorry, I understand now – Bob02 Jun 19 '20 at 22:03
-
Welcome to StackOverflow! Please take the [tour] and read "[ask]". And please don't post source code as screen shot, any text in general. – the busybee Jun 20 '20 at 20:31
1 Answers
0
You don't need to use the htons
or ntohs
functions for a uint8_t
variable, since it is only one byte. You htons
/ntohs
for uint16_t
variables and htonl
/ntohl
for uint32_t
variables.
Check this link, this might help you.

Roshin Raphel
- 2,612
- 4
- 22
- 40