Hello

I would like to encode a 2 16bit integer into a byte

than decode the 1 byte into 2 16bit integer ranges

something like this..

since both of the 16 bit integers only take up less half a byte 100% of the time.. I would like to be able to store them into a byte and be able to decode without any data loss...

like..

X = 3570
Y = 740

These are the ranges of X,Y 36x36 range
XArea
3570 / 36 = 99.1666667 which should be 100 because its overflowing the range
YArea
740 / 36 = 20.5555556 which should be 21 too because its overflowing the range.


Anyways I was thinking of using a signed byte to determine the decoding process accurately

like
if XArea is greater than YArea it would use positve numbers
if YArea is less than XArea it would use negivate numbers
and if both are equal to each other it would be 0 which would mean equality for X,Y.

Now Im trying to write both encode/decode in vb.net how should I do that?

vb Code:
  1. Shared Function EncodeArea(ByVal X As Short, ByVal Y As Short) As SByte
  2.         Dim XArea As Short = Math.Ceiling(X / 36)
  3.         Dim YArea As Short = Math.Ceiling(Y / 36)
  4.  
  5.         If XArea > 128 OrElse YArea > 128 Then Exit Function
  6.  
  7.         If XArea > YArea Then
  8.             'Positves.. 1 to 127 i guess..
  9.             'Something I don't know goes here
  10.         ElseIf XArea < YArea Then
  11.             'Negiavtes.. -1 to -128 i guess
  12.             'Something I don't know goes here
  13.         Else
  14.             Return 0
  15.         End If
  16.     End Function
  17.  
  18.     Shared Sub DecodeArea(ByVal Area As SByte)
  19.         Dim XMax As Short = 'Area And 127 idk decodedXArea
  20.         Dim YMax As Short = 'Area And -128 idk decodedYArea
  21.         Console.WriteLine("X Range MAX: " + XMax.ToString)
  22.         Console.WriteLine("Y Range MAX: " + YMax.ToString)
  23.     End Sub