• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to understand the syntax in arrays

 
Hareendra Reddy
Ranch Hand
Posts: 173
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....

Thanks in advance

[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: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And with BITS_PER_BYTE you mean Byte.SIZE, don't you?
 
James E Baker
Greenhorn
Posts: 23
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know more about bit maps and all these things. can anyone suggest me some resources on internet etc..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic