Page 1 of 1

Opening something in Hexadecimal

Posted: Sat Feb 02, 2008 11:55 pm
by Sinuvoid
How do I open something up in hexadecimal in Qbasic, then edit it?

Im guess it woudl go something like this....

Code: Select all

CLS
OPEN "test.exe" FOR BINARY AS #1

'a for next loop here
INPUT #1, hexnumbers%

CLOSE #1


Re: Opening something in Hexadecimal

Posted: Sun Feb 03, 2008 1:45 am
by Mac
Lee wrote:How do I open something up in hexadecimal in Qbasic, then edit it?
Read it

Code: Select all

CLS
PRINT "First 5 characters in test.exe"
PRINT
DIM X AS STRING * 1
OPEN "test.exe" FOR BINARY AS #1
FOR i = 1 TO 5
  GET #1, i, X
  PRINT ASC(X);
NEXT i
PRINT
CLOSE #1
To write, use PUT.

If you want hex, then convert the ASCII.

Mac

Posted: Mon Mar 24, 2008 1:23 am
by Michael Calkins
hex$(number) converts to hex
val("&h"+text) converst from hex.
you might want to zero pad the hex number

t$=hex$(asciivalue)
if len(t$)<2 then t$="0" + t

or perhaps

t$=string$(2-len(t$),&h30)+t$ 'adaptable to padding to more than 2 places.
Regards,
Michael