Xin
Xin

Reputation: 807

Why does 0x8FFFFFF equal 128MB?

I sometimes see code like this:

int length = 0x8FFFFFF; //128MB
byte buf = new byte[length];

It does not make much sense to me as:

0x8FFFFFF = 150,994,943
128MB = 128 * 1024 * 1024 byte = 134,217,728 byte

These two number does not equal. What am I missing here?

Thanks,

Upvotes: 2

Views: 5469

Answers (2)

user2350018
user2350018

Reputation: 9

Well, 0x7FFFFFF = 134217727, so 128MB should be 0x8000000

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799082

Someone previously had a 7 there but changed it to a 8 in order to avoid an off-by-one error, but forgot to change the rest to 0.

Upvotes: 6

Related Questions