Results 1 to 2 of 2

Thread: Adding hex to byte array

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2012
    Posts
    122

    Adding hex to byte array

    Hi !
    I need some help with this, im getting few addresses from memory that are dynamic and im using a pointer for this.However i noticed that when you read memory to a variable with type of string, the value is reversed and split to bytes (so if the value is B96F then in VB it shows me 6F-B9) i used to split the value and connect it again in reverse order, however its pretty much of code for such an easy operation.
    What i need to do is just to add &H30 to the pointer value, until now i was doing it like this:
    Code:
    'Note thats not the actual code, because im too lazy to write everything properly
    Dim val As String = BitConverter.ToString(ReadMemory(&HSomeAddress, 4), 0)
    
    Dim part1, part2, part3, part4 As String
    Split val to 4 parts by "-" signs
    Dim finalVal as string = "&H" + part4 + part3 + part2 + part1
    Dim TheAddressThatIsPointed As String = Hex(finalVal + &H30)
    However its lots of writing, isnt there a way to just read from this address and add directly some hex to it ?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Adding hex to byte array

    Yeah, the address is already in hex. There is no good reason to turn hex into a string unless you want to display it. You aren't displaying it, so don't turn it into a string at all. That just wastes time and makes your life more difficult. Hex is nothing but a certain way of representing a binary number. All numbers in computers are binary. You can represent them as decimal or you can represent them as Hex. We generally learn decimal, but hex makes more sense for representing a binary number. However, if you had a function that returned an Integer and you wanted to add 48 to it, would you take the integer, convert it to a string, convert it back to a number, then add 48? Not too likely, but that's exactly what you are doing in your code.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width