View Single Post
Old 04-19-2013, 10:32 AM   #181
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Quote:
Originally Posted by dimasic View Post
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.
knc1 is offline   Reply With Quote