Hex String to Integer

Welcome Forums General PowerShell Q&A Hex String to Integer

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 months, 2 weeks ago.

  • Author
    Posts
  • #104140

    Participant
    Points: 0
    Rank: Member

    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
    Points: 0
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      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

The topic ‘Hex String to Integer’ is closed to new replies.