[NTLK] Need NewtonScript help: How to convert an integer value to a hex string

Matej Horvat matej.horvat at guest.arnes.si
Tue Feb 15 21:21:00 PST 2022


There is indeed no such built-in function, and StrHexDump is 2.x-only.  
Here's one such function for a predetermined number of digits (not totally  
optimized):

func(What, Len)
begin
	local Digit;
	local Result;
	local Mask := 0xF << ((Len - 1) * 4);
	local Shift := (Len - 1) * 4;

	for i := 1 to Len do begin
		Digit := (BAnd(What, Mask) >> Shift) + Ord($0);
		if Digit > Ord($9) then
			Digit := Digit + 7;
		Result := Result & Chr(Digit);
		Mask := Mask div 16;
		Shift := Shift - 4;
	end;

	return Result;
end


More information about the NewtonTalk mailing list