just to be sure...

by Michael Calkins (Login MCalkins)
Moderator

 
i'm not sure what your generator needs to do, but, generally, compatibility aside, programs written in high level languages like QBASIC don't need to worry too much about endianness. I just want to make sure that you know that QBASIC can write little endian integers directly. For example:

DIM l as LONG

OPEN whatever FOR BINARY AS 1
PUT 1, , l
CLOSE

writes a LONG directly to the file, as a little endian 4 byte record. A QBASIC program can then read it directly with GET 1, , l. So, no manual conversion is required to read and write little endian numbers to files. So, since QBASIC expects little endian numbers in files and you say that the wav format also expects it, then i'm not sure why your program needs to worry about endianness at all. (Unless the generator needs to work with big endian encodings in a string format for some reason. You can work with the numeric values themselves and not worry about endianness, I think. Endianness is a low level concept dealing with encoding. The numeric values themselves are at a higher level, and have nothing to do with endianness.)

Regards,
Michael


'public domain, october 2011, michael calkins

DIM l AS LONG
DIM s4 AS STRING * 4
DIM t AS STRING
DIM i AS INTEGER
DIM s2 AS STRING * 2
DIM n AS INTEGER
DIM s1 AS STRING * 1

CLS

i = &H1234
s2 = MKI$(&H1234)       'converts an INTEGER to a 2 byte string (little end.)
l = &H89ABCDEF
s4 = MKL$(&H89ABCDEF)   'converts a LONG to a 4 byte string (little endian)

OPEN "delete.me" FOR BINARY AS 1
PUT 1, , i              ' writes an INTEGER directly
PUT 1, , s2             ' writes a 2 byte string
PUT 1, , l              ' writes a LONG directly
PUT 1, , s4             ' writes a 4 byte string

PRINT "File contents as bytes:"
FOR n = 1 TO LOF(1)
 GET 1, n, s1
 t = LCASE$(HEX$(ASC(s1)))
 IF ASC(s1) < &H10 THEN t = "0" + t

 'an alternative way to add leading zeros:
 ' t = STRING$(2 - LEN(t), &H30) + t
 'this is more suitable for lengths greater than 2.

 PRINT t; " ";
NEXT
PRINT
PRINT

i = 0
l = 0
s2 = ""
s4 = ""

PRINT "The values read back:"
GET 1, 1, i             'seeks to the beginning, reads an INTEGER directly
GET 1, , s2             'reads a 2 byte string
GET 1, , l              'reads a LONG directly
GET 1, , s4             'reads a 4 byte string
PRINT LCASE$(HEX$(i))
PRINT LCASE$(HEX$(CVI(s2)))     'converts a 2 byte string to an INTEGER (le)
PRINT LCASE$(HEX$(l))
PRINT LCASE$(HEX$(CVL(s4)))     'converts a 4 byte string to a LONG (le)

CLOSE

KILL "delete.me"
SYSTEM



    
This message has been edited by MCalkins on Oct 10, 2011 2:00 PM

Posted on Oct 10, 2011, 1:47 PM

Respond to this message   

Return to Index

Response TitleAuthor and Date
Ah, even betterLoudhvx on Oct 10
 * I'm glad that I was able to help.Michael Calkins on Oct 11
  *update. Program worked great. Thanks!Loudhvx on Oct 17

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement