If I want to transport a signed long (32 bit integer) across the network what do I do? If I send as a signed long then at other end I won’t know (potentially) how remote machine represents signed numbers? So what do I do?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
ntohl()operates on byte-order, so it doesn’t care much about the sign, all it cares for is how many bits are there. To answer the question in title.To answer the question “what do I do?” beyond stating that you’re asking question — you convert it to unsigned and then convert back on the other sign, because besides not knowing whether it’s signed or not, the arbitrary remote also doesn’t know what this number is about and your particular remote may be more knowledgeable of the matter.