Jump to content
  • 0

Question

Posted (edited)

Hi everyone,

I would like to convert the dword value (for example)

2020

to

hE4070000

in a script to speed up the search.

Is there a function known to do this or should I write my own?

Thank you all

Edited by MarioRossi93i

9 answers to this question

Recommended Posts

  • 0
Posted (edited)
7 hours ago, MarioRossi93i said:

A question bro, how to convert byte order?

Your func give 2020=000007E4

I need 2020=e4070000

is there an elegant solution like your code by any chance?

Thx again

function toHexStringBigEndian(val)
  local hex = "";
  local HEX_DIGIT_PATTERN = "%08x";
  local MAGIC_CHARACTER = ".."
  string.gsub(string.format(HEX_DIGIT_PATTERN, val):sub(-8),MAGIC_CHARACTER, function(x) hex = x .. hex end)
  return hex
end

Learn some string manipulation, it's fun to learn :). Search for "Regex".

Edited by ItsSC
wrong function name
  • 0
Posted
22 hours ago, MarioRossi93i said:

A question bro, how to convert byte order?

Your func give 2020=000007E4

I need 2020=e4070000

is there an elegant solution like your code by any chance?

Alternatively to the solution above by ItsSC, the following function can be used to swap endianness of a string that represents 4-byte hex value:

function swapEndianness(str)
  return (str:gsub('(..)(..)(..)(..)', '%4%3%2%1'))
end

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.