python - converting negative float numbers to unsigned int -


im trying send unsigned int data c server python client. requirement send negative float value client. number -5.700 , have 2 problems. 1) dont have clue on how retain negativeness within uint32_t, im using msb flag bit around it. fine? has better suggestions?

2) tried typecasting float 5.700 uint32_t, i.e uint32_t fops = *(uint32_t*)(&float_var) //float_var 5.700 , fops assigned value 0x00..40b66666 being sent python client. how retrieve float value @ client?

update: mats suggested python struct unpacks -ve floats there no need use flag bit.

the simplest solutions best: make string, , transfer that, rather binary floating point representation. way, don't have worry differences in floating point representation or how make python "understand" binary floating point value.

edit1: however, if transfer 32-bit integer python data object: expect floatdata = struct.unpack("f", data) should trick.

edit2: documentation struct.unpack (and struct.pack)

edit3: struct.unpack assume both machines use same floating point format. means software isn't portable. should work ok on commonly available platforms.


Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

java - Jtable duplicate Rows -

java - Run a .jar on Heroku -