2147483647

You must be thinking i put a random number as title. You are wrong! It is a very special number. You will see why.

I am working on FBConnect plugin for MyBB. It was storing Facebook UID’s in an “int(15)” field in a MySQL database. Everything seemed to work perfectly until i tested the registration process with an account whose Facebook UID is a 15 digit number. It just kept storing the number 2147483647.

I spent the whole day revising my codes. They all seemed OK. I was really puzzled. Then i thought: Why not google the number?

232 – 1 = 2147483647
231 – 1 = 2147483647

Whats so special about it? In fact, it is the biggest number that can be made using a 32-bit binary number system I thought it was the higheest number that was possible with a 32-bit binary number system. But i was wrong. Thanks to the clarifications Rick Hemstra, i found out it is half the greatest number possible with a 32-bit binary number system. This is because this MySQL field also hold negative values. Therefore, the maximun number decreases by half.

The solution:-
All i had to do is to change the field type to “bigint(15)”. The new limit is now:
263 – 1 = 9,223,372,036,854,775,807 😀

Problem solved 🙂

4 thoughts on “2147483647

  1. 2^32 – 1 = 4294967295 not 2147483647. The reason your variable can only hold 2147483647 is because it’s a signed int which can hold positive as well as negative values. 🙂

  2. Thanks Rick Hemstra. You are right.I just found this info on the net without verifying.

    Therefore, (2^32)/2 – 1 = 2147483647

Leave a Reply

Your email address will not be published. Required fields are marked *