I have a 4 byte hexadecimal value that I have a script to print out, But I want to now take that value then subtract the value C8 from it 37 times and save them as different variables each time, But the problem is I don't know how to do hexadecimal calculations in lua, If anyone can link me to any documentation on how to do this then that would be much appreciated.
Asked
Active
Viewed 1,079 times
2 Answers
1
You can make a hexadecimal literal in Lua by prefixing it with 0x
, as stated in the reference manual. I found this by googling "lua hex"; such searches usually get good results.
"Hexadecimal numbers" aren't anything special, hexadecimal is just a way to represent numbers, same as decimal or binary. You can do 1000-0xC8
and you'll get the decimal number 800
.

Putnam
- 704
- 4
- 14
0
Code to convert:
function convertHex()
local decValue = readInteger(0x123456);
hexValue = decValue
end
function hexSubtract()
for i = 1,37 do
local value = 0xC8
hexValue = hexValue - 0xC8
result = hexValue
if i == 37 then
print(result) --Prints dec value
print(string.format('%X',result)); --Prints hex value
end
end
end
Replace 0x123456
with your address, use those functions like this convertHex(),hexSubtract()

Masoud Keshavarz
- 2,166
- 9
- 36
- 48

Frouk
- 1
- 1