• Register
Forum Thread
  Posts  
LUA question.... (Forums : Coding & Scripting : LUA question....) Locked
Thread Options
Nov 25 2014 Anchor

I've decided to try and learn some programming with LUA and I'm stuck on an exercise.
These are introductory level exercises that help you familiarize yourself with LUA.

Can someone tell me how I can find 2 to the 16th power without any mathematical operators or typing in the answer in decimal form?
It also hints that I should google "base16 literals", but I'm still lost.

I appreciate any help.

print(2^16)
Nightshade
Nightshade Unemployed 3D artist
Nov 25 2014 Anchor

You should type it in this format:
0x3b24

So 2 to the power of 16 should be 0xffff ?
base16 is just another name for hexadecimal (just as base2 is another name for binary)

Edited by: Nightshade

--

   - My portfolio
“There he goes. One of God's own prototypes. Some kind of high powered mutant never even considered for mass production. Too weird to live, and too rare to die.” Hunter S. Thompson

Dec 2 2014 Anchor

Just out of interest: why would you want to use base 16 literal hex codes?

2^16 is the equivalent of 2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2

Here is a little code example I wrote for a wiki:

local a, b = 2, 16
local result = a ^ b -- generate answer
 
-- break down power function into string result (ignore this code)
function power(i1, i2)
 local val = "" -- clear string
 --+--
 for i = 1, i2 do -- generate the longhand math formula
  if i < i2 then val = val..i1.."*" else val = val..i1 end
 end
 return "which is the equivalent of " .. val
end
 
print("power value of "..a.." and "..b.."  = " .. result, power(a,b))

P.S: It's Lua not LUA, but no worries! :)
P.P.S: Sorry I don't really know much about hex values as I've not really used them in Lua before other than for setting the tint of characters in the game engine I use.

Edited by: AFRLme

Feb 19 2015 Anchor

It also hints that I should google "base16 literals", but I'm still lost.

______________________
aliiii

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.