Peek hex string?

Just starting out? Need help? Post your questions and find answers here.
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Peek hex string?

Post by Justin »

what would be the best way to return the contents of a memory area as an hex string?, the fact that pb works always with unsigneds messes me a bit

peekHEX(address,len)
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post by Proteus »

Try these procedures:

Code: Select all

Procedure.s PeekHEXByte(*Address)
  ProcedureReturn RSet(Hex(PeekB(*Address)), 2, "0")
EndProcedure

Procedure PeekHEXWord(*Address)
  ProcedureReturn RSet(Hex(PeekW(*Address)), 4, "0")
EndProcedure

Procedure PeekHEXLong(*Address)
  ProcedureReturn RSet(Hex(PeekL(*Address)), 8, "0")
EndProcedure

Procedure.s PeekHEX(*Address, len)
  Out.s = ""
  For a = 0 To len-1
    Out + PeekHEXByte(*Address+a)
  Next
  ProcedureReturn Out
EndProcedure
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Post by Justin »

It does not work, at least is not what you would see in an hex editor, you have to convert to unsigned, this worked

Code: Select all

procedure.s peekHEX(mem,bytes)
	st$=""
	for x=0 to bytes-1
		vs.b=peekb(mem+x)
		vu.w = vs & $FF
		h$=hex(vu)
		if len(h$)=1 : h$="0" + h$ : endif
		st$=st$ + h$
	next
	procedurereturn st$
endprocedure
Post Reply