u/AevenDev

Negative hashes and InternalMemory instructions, How do?

Negative hashes and InternalMemory instructions, How do?

So, let's say im making a script to automatically print a set amount of an item. Sometimes the PrefabHash of this item is gonna be negative (for example the "Kit (Portable Gas Tank)" with a hash of "-1061945368")

As i think i understand this number would be represented in binary with the first bit defining the sign, so something like "10000010101000111110110..." (This is not the real binary representation of the previously mentioned hash, as i could not find a way to convert it to binary)

Then in order to write the ExecuteRecipe instruction we need to convert this 64bit hash into a 32bit hash as shown in the page for the printer:

https://preview.redd.it/r45ps0mai4kh1.png?width=947&format=png&auto=webp&s=0af4b2850caceda9bd1b1a8d92180d2c25f93dda

For non negative numbers is as easy as just doing "sll shifted_hash positive_hash 16" to shift 16 bits to the left.

But doing this with a negative hash we'd end up loosing the sign bit in the process.
Can i simply do a "sll r0 sign_bit 47" to get the correct sign bit at the expected position to then add up to the rest of the instruction? Or is the process more complicated? because while trying to figure this out i've come across videos of people talking about about using sla instead of sll but they did not elaborate further...

Has anyone attempted this and can shine some light?

reddit.com
u/AevenDev — 2 days ago