I would like to simulate byte overflow in VB.NET. The code below achieves the correct result but I suspect this is not the most efficient method. Is there a simpler/better way to achieve this?
Dim src As Byte = 232
Dim key As Byte = 231
Dim encoded As Byte = 0
Dim decoded As Byte = 0
' Encode
encoded = CByte((CInt(src) + CInt(key)) Mod 256I)
' Decode
Dim tmp As Int32 = CInt(encoded) - CInt(key)
decoded = CByte(IIf(tmp < 0, 256I + tmp, tmp))
' encoded = 207
' decoded = src = correct