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:
Shared Function EncodeArea(ByVal X As Short, ByVal Y As Short) As SByte Dim XArea As Short = Math.Ceiling(X / 36) Dim YArea As Short = Math.Ceiling(Y / 36) If XArea > 128 OrElse YArea > 128 Then Exit Function If XArea > YArea Then 'Positves.. 1 to 127 i guess.. 'Something I don't know goes here ElseIf XArea < YArea Then 'Negiavtes.. -1 to -128 i guess 'Something I don't know goes here Else Return 0 End If End Function Shared Sub DecodeArea(ByVal Area As SByte) Dim XMax As Short = 'Area And 127 idk decodedXArea Dim YMax As Short = 'Area And -128 idk decodedYArea Console.WriteLine("X Range MAX: " + XMax.ToString) Console.WriteLine("Y Range MAX: " + YMax.ToString) End Sub




Reply With Quote