Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

LUA: byte to nibbles (low/high)

Hello,

I need to convert raw hex data: "10 55 55 59 93 09 22 f0" into string: "0f22903995555501" but how to extract high/low nibbles from individual byte ?

function userdata2bcd(buffer, offset, len)
  local bytearr = {}
  for i = 1, len do
    num = userdata2dec(buffer, offset+len-i, 1)
    highByte = ...
    lowByte  = ...
    bytearr[i] = tostring(lowByte) .. tostring(highByte)
  end
  return table.concat(bytearr)
end

Any suggestion is appreciated...

Thx, A!