Re: pack/unpack pos to binary

By eeew, 6 Years ago (2013-09-21 14:51:23), written in Lua, viewed 429 times. This paste is a reply to pack/unpack pos to binary by eeew
URL https://paste.godclan.hu/view/66Od5M8- Embed
Download Paste or View RawExpand paste to full width of browser
  1. function packpos(x, y, z)
  2.     x = 819200+math.floor(x*100) -- -8192 - 8192   3 byte
  3.     y = 819200+math.floor(y*100)
  4.     z = math.floor(1300*65535/(z+100)) -- -100 - 1200   2 byte
  5.     return string.byte(
  6.         x, BitExtract(x, 8, 8), BitExtract(x, 16, 8),
  7.         y, BitExtract(y, 8, 8), BitExtract(x, 16, 8),
  8.         z, BitExtract(z, 8, 8))
  9. end
  10.  
  11. function unpackpos(string, startindex)
  12.     local x1, x2, x3, y1, y2, y3, z1, z2 = string:byte(startindex, startindex + 7)
  13.     return  ((x1 + x2*256 + x3*65536) - 819200)/100,
  14.             ((y1 + y2*256 + y3*65536) - 819200)/100,
  15.             (z1 + z2*256)/65535*1300 - 100
  16. end
  17.  

Replies to Re: pack/unpack pos to binary rss

Title Name When
Re: Re: pack/unpack pos to binar eeew 6 Years ago.

Reply to "Re: pack/unpack pos to binary"

Here you can reply to the paste above