Jump to content

Convert Decimal FormID to Hexadecimal


dylbill

Recommended Posts

So I finally got a function working to convert a formID to Hexadecimal after using the .GetformId() function by converting first to binary and then to hex. Here's the relevant code if anyone is interested. Requires SKSE.

 

  Reveal hidden contents

 

My Question is, does anybody know if negative FormID's always start with FF? Because that's what this function assumes. I've tried looking around skyrim for negative ID's and this seems to be the case. Negative IDs occure when using placeAtMe to create new object references, and they all seem to start with FF too. Any help would be appreciated!

 

 

Link to comment
Share on other sites

I guess I should be more specific. Sometimes when calling the .GetFormId() function, it returns a negative number, and yes I've found this is for created items in game. Example: -16773862 according to Skyrim is FF000D1A in hex. According to a programmer calculator it is FFFF FFFF FF00 0D1A‬. If I didn't put an FF in front manually for the negative number, my function would return 000D1A. I was wondering if it's always an FF in front for negative ID's, or if there are exceptions. I also remember when I was trying to do this a while ago, the mod follower Recorder returned a negative ID, so I'm just trying to make sure the function is accurate.

Edited by dylbill
Link to comment
Share on other sites

Didn't you aware of using modulo? So there is not required any SKSE function.

 

maybe next function is working as you like

  Reveal hidden contents

 

Edited by ReDragon2013
Link to comment
Share on other sites

Hey thanks, I didn't think of using modulo. You still have to account for negative numbers though. I modified your code to do so and it works!

 

 

  Reveal hidden contents

 

 

Thanks a bunch!

Edited by dylbill
Link to comment
Share on other sites

One more thing, using the hexDigits array is faster than using the if, andif conditions. So here's the code modified for that:

 

 

  Reveal hidden contents

 

 

Thanks again!

Link to comment
Share on other sites

One last tweak. For negative numbers you can just use another array to find the hex digit, instead of turning to positive and inverting:

 

 

  Reveal hidden contents

 

Edited by dylbill
Link to comment
Share on other sites

I do not believe it's a good idea to use array(s) for this kind of function. I would like to use that as convenience without any initialization.

My final version would look as follow with minimum of function variables inside. Just in case the parameters for string and bool may be stripped, if that is desired

the last code lines for appending a string to the return value should be removed as well.

 

 

  Reveal hidden contents

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...