You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Union BtoLEnd
b(1) as Byte
i as Integer
End Union
Function etc
Local Sp as Dword
local BE as BtoLend
Dim TempByte(1 to Len(TempString$)) as Byte at StrPtr(TempString$)
BE.b(1) = TempByte(25)
BE.b(0) = TempByte(26)
' the little ended integer is now in BE.i
Thanks Pierre, I knew about the multiple bytes and just hadn't worried about it for the question. Didn't know about "DIM AT", so I'll look at that as well. It seems like my programming comes in bursts, and I tend to forget everything in between ;-(
The next line is wrong,
TEMP4L = HEX$(ASC(MID$(TempStr, 25, 1)))
you need to have
TEMP4L = HEX$(ASC(MID$(TempStr, 25, 1)), 2)
becose, with the manipulation you do,
this byte in hex must be represented by 2 characters, (0x00 to 0xFF)
and you will need the leading zero if the byte value is under 0x10.
For example: 0x01 0x02 got to become 0x0102 and not 0x0012.
You may also consider doing it as a WORD data type:
Code:
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN () AS LONG
LOCAL TEMP4H,TEMP4L,tempStr AS STRING
LOCAL temp5 AS WORD
tempStr = "dfuitfguiti67y9o7yoigyiesdjuwj3we7373yuweshdehdehedeue"
TEMP4H = HEX$(ASC(MID$(TempStr$, 26, 1))) 'high byte sample rate
TEMP4L = HEX$(ASC(MID$(TempStr$, 25, 1))) 'low byte sample rate
TEMP5 = VAL("&H" & TEMP4H & TEMP4L)
? STR$(TEMP5)
TEMP5 = CVWRD(TempStr$, 25)
? STR$(TEMP5)
END FUNCTION
I want to pull big-endian hex data out of a small wav file loaded into a string. The following works (needs to be expanded for more bytes), but just seems clumsy and indirect. Can anyone "pointer" me in a better direction?
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: