Borderlands 2 Compatibility Pack Pricing

by Tom Richards

Tuesday, October 09, 2012

Why did the Borderlands 2 compatibility pack cost -1 MSP, and then 4,294,967,295 MSP, simultaneously? Well, somebody derped. Whether it was Gearbox or Microsoft, I’m not sure.

Here’s a very short C code example of this problem.

#include <stdio.h>
int main()
{
    int realPrice = -1;
    unsigned int derpPrice = realPrice;

    printf("Real price: %d\n", realPrice);
    printf("Derp price: %u\n", derpPrice);

    return 0;
}

The output of this program is:

Real price: -1
Derp price: 4294967295

Wait, what? I didn’t type that crazy four-billion number in my source code anywhere. So what happened?

Line 5 of the code was executed, and caused this headache.

realPrice is a signed integer, which means that it can hold any number between −2,147,483,648 and 2,147,483,647. That’s lovely; -1 will be stored there just fine. But when we tell the computer, “Hey! The value -1 should be stored in the unsigned integer called derpPrice,” we have problems. This is because an unsigned integer can hold numbers between 0 and 4,294,967,295. Did you catch that? -1 is not in that range. If we try to store a negative number there (in derpPrice), it will show up as a really large positive number. Usually it will be some number above 2,147,483,647.

I don’t know what all that fancy code stuff means. Why did -1 turn into 4,294,967,295?

In order to store negative numbers in a computer, we use something called the Two’s Complement representation of a number. If we want to convert a number into its Two’s Complement representation, we follow these steps:

  1. Convert the number to binary as a positive number.
  2. Flip all the bits (1 becomes 0, 0 becomes 1).
  3. Add 1 to the number (in binary).

Let’s do this for -1.

  1. Convert -1 to binary. 000000012

  2. Flip all the bits. 111111102

  3. Add 1. 111111112

The computer would store -1 as 111111112 in a signed representation, assuming our numbers are only 8 bits.

Unfortunately, our value 111111112 was forcibly converted into an unsigned representation. Now it can now only be a positive number. 111111112 = 25510

In Microsoft Points world, however, numbers are represented with 32 bits. We can apply the same series of steps to find that the 32-bit representation of -1 becomes a really big number.

111111111111111111111111111111112 = 4,294,967,29510


tl;dr I guess I’m not playing Borderlands 2 anytime tonight.