Quote:
Originally Posted by dimasic
I know this. But when we divide the XX byte by 16 and then multiply the result by 16, we'll got X0. It's the right thing we want to get, but not in the case of FF - we'll got F0 and the greyish background in screenshot. When we are solving the problem by mathematical, not the bitewise ops, we must add the "if - then" case for FF bytes. IMHO, XX bytes instead of X0 in the resulting file are not the problem at all, but our code is more simple, without if-then and math.floor.
|
True - the only native numeric type in a **standard** build of Lua is Double - - but that does not mean you need to load the math library.
Code:
core2quad ~ $ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> str = 'ABC'
> print (string.format ('%X', str:byte(2)))
42
> print (string.format ('%X', str:byte(2)/16))
4
> os.exit()
core2quad ~ $
Which certainly looks like a right-shift-4 to me.