lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Sep 22, 2008 at 11:08 AM, Jeff Wise <jwise@sealyrealty.com> wrote:
> I need to define 3 bytes of hex data. I originally used:
>
>      local hunted = 0xD3A8AF
>
> This gave no errors but the program did not work. When I discovered 'hunted'
> was the culprit, I used:
>
>      local h1 = 0xD3
>      local h2 = 0xA8
>      local h3 = 0xAF
>      local hunted = h1 .. h2 .. h3
>
> This worked. I can not believe this is necessary. What am I missing?

the same thing you've missing in your other posts: value typing.

0xD3 is a Number, it's synonymous to 211, not to a byte, or a
character. 0xD3A8AF is also a number, synonymous to 13871279. even
worse, in Lua all numbers are floating point, so these are 211.0, and
13871279.0

if you want a three character string with each character specified in
hexadecimal, use:

string.char (0xD3, 0xA8, 0xAF)


-- 
Javier