Opening something in Hexadecimal

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Opening something in Hexadecimal

Post 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

Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Re: Opening something in Hexadecimal

Post 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
User avatar
Michael Calkins
Veteran
Posts: 76
Joined: Tue Apr 05, 2005 8:40 pm
Location: Floresville, Texas
Contact:

Post 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
Post Reply