Hex String to Integer

This topic contains 2 replies, has 2 voices, and was last updated by  Dave Turner 1 week, 3 days ago.

  • Author
    Posts
  • #104140

    Dave Turner
    Participant

    Hi all,

    Definite newbie here so bear with me. 🙂

    I have a script that pulls a hex string from a file in the format A5B7. It will always only be four digits. I need to have that hex string converted into a numeric value such as an Int16 or something similar. I'm usually good at Google but I can't seem to find what I need.

    Thanks!
    -Dave

  • #104141

    bob
    Participant

    You will need to first make it a legitimate hexadecimal number by prefixing "0x" to the number. Now cast it to an integer, in Powershell cast look like this [type]

    [int] 0xA5B7

    42423

    • #104143

      Dave Turner
      Participant

      Bob,

      My thanks for an amazingly simple solution. I had it right except that I didn't put on the prefix "0x" to make the hex string a hex number. I didn't even need to convert it – I just put on the prefix and assigned it which made the variable a number.

      Many thanks!
      -Dave

You must be logged in to reply to this topic.