• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to understand the syntax in arrays

 
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And with BITS_PER_BYTE you mean Byte.SIZE, don't you?
 
Greenhorn
Posts: 23
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic