home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / _+Compress509431252002.psc / Cod_Differ.bas < prev    next >
Encoding:
BASIC Source File  |  2001-10-18  |  1.4 KB  |  47 lines

  1. Attribute VB_Name = "Cod_Differ"
  2. Option Explicit
  3.  
  4. 'This coder calculates the difference between two codes
  5. 'if the first code = 20 and the second code = 15 then then difference
  6. 'between those two = -5
  7. 'because negative numbers can't be stored in a byte and the range
  8. 'can go from -128 to +127, the 0 is stored as 128 so the
  9. 'value -5 will become -5+128=123
  10. '  0 = -128
  11. '127 = -1
  12. '128 = 0
  13. '129 = 1
  14. '255 = 127
  15.  
  16. Public Sub Difference_Coder(ByteArray() As Byte)
  17.     Dim X As Long
  18.     Dim LastCode As Integer
  19.     Dim NewCode As Integer
  20.     Dim OutStream() As Byte
  21.     LastCode = ByteArray(0)
  22.     For X = 1 To UBound(ByteArray)
  23.         NewCode = LastCode - ByteArray(X)
  24.         If NewCode < -128 Then NewCode = NewCode + 256
  25.         If NewCode > 127 Then NewCode = NewCode - 256
  26.         NewCode = 128 + NewCode
  27.         LastCode = ByteArray(X)
  28.         ByteArray(X) = NewCode
  29.     Next
  30. End Sub
  31.  
  32. Public Sub Difference_DeCoder(ByteArray() As Byte)
  33.     Dim X As Long
  34.     Dim LastCode As Integer
  35.     Dim NewCode As Integer
  36.     Dim OutStream() As Byte
  37.     LastCode = ByteArray(0)
  38.     For X = 1 To UBound(ByteArray)
  39.         NewCode = ByteArray(X) - 128
  40.         LastCode = LastCode - NewCode
  41.         If LastCode < 0 Then LastCode = LastCode + 256
  42.         If LastCode > 255 Then LastCode = LastCode - 256
  43.         ByteArray(X) = LastCode
  44.     Next
  45. End Sub
  46.  
  47.