Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# unable to understand the syntax in arrays

Hareendra Reddy
Ranch Hand
Posts: 173
Hello all,

While i am going through some code, i encountered the following code...

Can some one explain what those hexadecimal number doing inside srray subscipt....

[EDIT]
thank you all... i just tried printing the array length it is just another way to provide size...
still doesnt understand what the "/8" is doing...

Campbell Ritchie
Sheriff
Posts: 48954
60
You want a new byte array large enough to hold all the values from 0 to 0xffffffff inclusive. You are using this as a bitmap, where each value uses 1 bit. Instead of writing false-true-false-true-false-true-false-true, you can write 01010101 and be sure to squeeze those 8 boolean values into 8 bits (1 byte).
So to fit all the values from 0 to 0xffffffff in, you need not 0xffffffff bits, but 0x20000000. That is 0xffffffff / 8.

Campbell Ritchie
Sheriff
Posts: 48954
60
I earlier wrote: . . . 0x20000000. That is 0xffffffff / 8.
Try it and see. You will see that 0xffffffff / 8 is 0x20000000 0x1fffffff.

So, either my interpretation of 0 to 0xffffffff is mistaken, or the arithmetic is mistaken and it should read 0xffffffff / 8 + 1.

Actually, it is bad style to write numbers out like that. It would have been better to write
TOTAL_NUMBER_OF_BITS / BITS_PER_BYTE + (TOTAL_NUMBER_OF_BITS % BITS_PER_BYTE == 0 ? 0 : 1)

Rob Spoor
Sheriff
Posts: 20529
54
And with BITS_PER_BYTE you mean Byte.SIZE, don't you?

James E Baker
Greenhorn
Posts: 23
• 1
Just a small note... the original post asked about 0xFFFFFFF not 0xFFFFFFFF. It may be a typo or it may not, but I thought I'd mention it.

Hareendra Reddy
Ranch Hand
Posts: 173
I want to know more about bit maps and all these things. can anyone suggest me some resources on internet etc..