concatenation issue (RESOLVED)

I’m trying to implement a int-to-hex algorithm, but for whatever reason i can’t get concatenation to occur with this recursive function:

-- this is line 46:
recursion = ""
hexTable = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" }
toHexResult = ""

function toHex( d )
  print( recursion .. "toHex", d ) -- prints properly 
  recursion = recursion .. " "
  local r = d % 16
  local result = ""
  if( d-r == 0 ) then 
    toHexResult = hexTable[r]
  else
    toHexResult = toHex( (d-r)/16 )
    print( "toHexResult", toHexResult )
    toHexResult = toHexResult .. hexTable[r] --this is line 60
  end
  print( recursion, "result ", toHexResult )
  return toHexResult
end

passing in 24576 (enough to cause recursion a few times)
the output is:

toHex   24576
  toHex    1536
    toHex    96
      toHex    6
      result    5
toHexResult      5
error: [string "-- Creating a sound buffer object..."]:60: attempt to concatenate field '?' (a nil value)

figured it out!

i forgot that arrays (tables) start at index=1, not 0. hexTable[r+1] is what is needed.