October 31, 2025, 11:55:30 AM

News:

IWBasic runs in Windows 11!


Conversion Head Scratcher

Started by LarryMc, June 21, 2009, 01:09:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

Found some code in the old forums that was written in ibasic that I want to use.

I plugged it in to CBasic and it worked fine.

Converted it over to EB and it doesn't work fine.

Adjusted the code in CB so that I could copy the identical code into EB.

The following code produces one result in CB and a different result in EB.

It's doing the calculations different somehow.
Easy way to spot the diff is look at the 1st line of text output.
In the CB version there is a jj around the middle of the line and it isn't in the EB version.

Attached is the jpg I was using for input.

Anyone got any ideas.

   Dim File1 As File
   Dim File3 As Bfile
   Dim Quanta,ByteNo As Int
   Dim OneLine As String
   Dim Byte As Char
Dim OneByte As Char
dim tb,flen as int
   Dim Bytes,ByteCount As Uint

dim fname_in, fname_out as string
fname_in=GETSTARTPATH+"back.jpg"
fname_out=GETSTARTPATH+"back.txt"
   OpenFile(File3,fname_in,"R")
   OpenFile(File1,fname_out,"W")

OneLine=""
flen = 4*Ceil(Len(File3)/4-1)
   For Quanta=0 To flen Step 4
'Read four bytes and convert them to an unsigned integer:
Bytes=0
      For ByteNo=0 To 3
      Read(File3,Byte)
         Bytes=Bytes+256^ByteNo*(Byte&255)
      Next ByteNo
      'Encode the unsigned integer into five characters:
      For ByteNo=4 To 0 Step -1
      OneLine=OneLine+Chr$(Bytes/85^ByteNo+35)
tb=(85^ByteNo)
         Bytes=Bytes% tb 
      Next ByteNo
      If Len(OneLine)=65
      Write File1,OneLine
         OneLine=""
      EndIf
Next Quanta     
   'Write any remaining data:
   If Len(OneLine)
Write File1,OneLine
   EndIf
   CloseFile File3
   CloseFile File1
end
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

aurelCB

I dont understand what is the purpose of this program?
Look interesting...

LarryMc

To encode

But the purpose of the program has no impact on why it gives different results. ;)

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

Don't have time to try it.  But the difference in calculation probably has to do with the divisions.

In Emergence, like most compilers, the result of a division is at the highest precision of the numerator or denominator.  Interpreters and scripting languages usually just do everything in floating point without regard to the type, which is also why they tend to be much slower ;)

1/2 = 0 in Emergence
1/2 = .5 in Creative

Because 1 and 2 are both integers the result is an integer in Emergence/Aurora.  Which is why we have type modifiers:

1/2f = .5
1f/2 = .5

Or

1.0/2.0 = .5

Why would you want to encode 4 bytes into 5?

Paul.
Ionic Wind Support Team

LarryMc

Quote from: Paul Turley on June 21, 2009, 01:28:21 AM
Why would you want to encode 4 bytes into 5?
Encode binary data into text so that it can be stored like strings.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library