none
my simple compressor of random info RRS feed

  • General discussion

  • i make a base change from binary but instead of adding the reminder i alternatively add it and substract it:

    re:

    TextWindow.WriteLine("enter random number to compress")

    number=TextWindow.Read()


    dectobin()


    compresion()
    TextWindow.WriteLine(number+" compressed number:")
    decompresion()
     
    bintodec()
    TextWindow.WriteLine(number+" decompressed number: ")

    Goto re

    Sub bintodec
    numero=0
    For i=1 To Text.GetLength(number)
        dig=Text.GetSubText(number,i,1) 
        numero=numero*2+dig
      EndFor
      number=numero
    EndSub


    Sub dectobin
      numero=""
      While number>0
        dig=Math.Remainder(number,2)
        numero=Text.Append(dig,numero)
        number=Math.Floor(number/2)
      EndWhile
      number=numero
    EndSub

    Sub compresion

    numero=0
    flag=1
    j=0
    While j<Text.GetLength(number)
    j=j+1
    dig=text.GetSubText(number,j,1)
    flag=flag*(-1)
      numero=numero*2-dig*flag
    'TextWindow.WriteLine(numero)
      EndWhile
    number=numero
    endsub


    Sub decompresion

    numero=""
    repeat:
    savednumber=number
    While number>0
     'TextWindow.WriteLine(number)
    dig=Math.Remainder(number,2) 

    number=(number+dig*flag)/2
    flag=flag*(-1)
      numero=Text.Append(dig,numero) 
    EndWhile
    l=Text.GetLength(number)
    If Math.Remainder(l,2)=0 Then
      flag=-1
      number=savednumber
      Goto repeat
    EndIf

    number=numero
    EndSub

      

    edit:

    actually the program is wrong, i saved without noticing the variable flag

    • Edited by antonio glez Wednesday, October 30, 2019 12:44 PM
    Monday, October 28, 2019 6:26 AM