Convert number from decimal do hex

How to convert number from decimal do hex when you have negetive integer?

Negative integers are usually represented as two’s complement values. For two’s complement to be useful, you need to know how big the storage space is because all of the high order bits are filled with 1s.

Here’s a function that given a negative number and the width of the storage space in bytes. For example, if you want to store -3 in a 1 byte wide space, it will yield FD. If you up the bytes to 4, you’ll get FFFFFFFD.

blocks (36)

Hint: You should be able to drag and drop the image into the blocks workspace in App Inventor to add it to your project.

1 Like

Beware - AI2's idea of hex is not compressed.
If you need compressed hex, see the math faq

1 Like

Thank you very much Evan it works perfectly :smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.