![]() |
|
[C] Endian read/write - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Endian read/write (/showthread.php?tid=6063616) |
Endian read/write - zNinja - Apr 5, 2020 Hi, I am trying to figure out if I am doing something wrong by swapping bits of floats to big endian and back to little endian on little endian machine. I am able to convert float and double to bit endian, write to file, read from file and convert back to little endian on my project. I tried to use nodejs to check correctness of my implementation. I get right conversion of double from file, but float precision is incorrect. C++ test PHP Code PHP Code PHP Code Nodejs output PHP Code I need help to figure out is my implementation wrong or nodejs treats floats as other type/size? EDIT: Just figured out with this test. Nodejs does not read floats as expected. PHP Code RE: Endian read/write - saltycracker - Apr 5, 2020 Curious about these two lines... Code float l_f = nw_writeFloatBE(5.1);You spend the time creating two variables here: Code float l_test_f = 5.1;And then use literals in the function calls.. I know. Picky. Good work BTW.. Its nice to see something that C++ was designed to handle. RE: Endian read/write - zNinja - Apr 5, 2020 (Apr 5, 2020 06:30 AM)saltycracker Wrote: Curious about these two lines...I have edited the code multiple times in short period to eventually pass some test standards and show results. (Apr 5, 2020 06:30 AM)saltycracker Wrote: Good work BTW.. Its nice to see something that C++ was designed to handle.Thanks. RE: Endian read/write - Mysticism - Apr 5, 2020 Floating point arithmetic can sometimes be tricky and a pain in the ass so this is well-common |