aspose file tools*
The moose likes Beginning Java and the fly likes unable to understand the syntax in arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "unable to understand the syntax in arrays" Watch "unable to understand the syntax in arrays" New topic
Author

unable to understand the syntax in arrays

Hareendra Reddy
Ranch Hand

Joined: Jan 09, 2011
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....

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

Joined: Oct 13, 2005
Posts: 39409
    
  28
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

Joined: Oct 13, 2005
Posts: 39409
    
  28
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

And with BITS_PER_BYTE you mean Byte.SIZE, don't you?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
James E Baker
Greenhorn

Joined: Jul 28, 2011
Posts: 23
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

Joined: Jan 09, 2011
Posts: 173

I want to know more about bit maps and all these things. can anyone suggest me some resources on internet etc..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to understand the syntax in arrays