简体   繁体   中英

Represent negative numbers in other bases

How do I represent negative numbers in non-10 bases, eg say in base 20 . I know how to do this in binary using two's complement, but what would the equivalent of two's complement be in other bases ?

For example, in base 20, the denary number 100 is represented as 50 . How would I make this 50 signed? Would I need to convert it to binary, two's complement it, the convert it back to base-20? It seems a little long-winded.

In that case, negative base-20 50 (which is 100 in base-10) would be 7g , and positive would be just 50 . But is this the standard way to represent negative numbers in other bases?

The generalisation of two's complement is radix complement .

The radix complement of an digit number y in radix is, by definition, −. The radix complement is most easily obtained by adding 1 to the diminished radix complement, which is ( −1)−

We must however agree what is. For instance, in binary we may say we have 32 bits, so = 32 in that case.

So for the example of base-20 we should make some definitions:

  • The digits are "0123456789ℎ".
  • is 10 (an arbitrary choice, but it has to be made)

We can also define what the "(diminished) complementary digit" is for each digit. It is the digit that when added to the first will always yield the greatest digit ( 20 in this case). For example 2 20 + ℎ 20 = 20 , so ℎ 20 is the complement of 2 20 , and vice versa.

For your example number 50 20 , we proceed as follows:

Replace every digit of the -digit representation with its complement:

So the diminished complement of 0000000050 20 thus becomes 20

To get the negation of 50 20 we just need to add 1 to that:

−50 20 = 0 20

It is important to not reduce this representation to use fewer digits -- we have to stick with the -digit representation, otherwise it is not clear when a number is positive or negative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM