Jump to content
  • 0

Dword value conversion


MarioRossi93i
 Share

Question

9 answers to this question

Recommended Posts

  • 0
2 hours ago, CmP said:

Check if the following solution suffices for your case: 

How to goto a pointer in a script? (#7hphwlq4)

 

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

Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

  • 0
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
Link to comment
Share on other sites

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
 Share

×
×
  • 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.