Search code examples
binarybitunsignedsigned

How to differ unsigned n bit from signed n bit?


is it possible to differ unsigned n bit from signed n bit?

Since they look just the same, e.g. 10001111 can either presents 143 or -113


Solution

  • It's impossible, and it's not the only impossible thing. In common case you cannot even be sure that 10001111 represents 143, -113 or 42. You may invent your own way of mapping all possible binary octets to numbers or any other imaginary entities.

    For example, you may treat a 64-bit integer as an efficient representation of 16-permutations: such an integer consists of 16 nibbles and each of them may take 16 different values. Then you can implement permutation composition using bit-shift and bitwise logic instructions of common processors or implement your own permutation processor on (for example) FPGA with almost single-cycle permutation composition.

    It's also true for any other operations on any objects you can imagine.