I would like to pack 2 floats into an long long. What would be the correct way to do this?
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.
Slightly depends how portable you want it to be, in two senses: what platforms it works on at all, and what platforms it gives the same answer on. But something like this.
The “other” way to get the bits of a float as an integer in one write+read is with a so-called “union cast”, but I prefer memcpy. You can also access the float one
unsigned charat a time and build up thelong longwith 8-bit shifts.