Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    outsorts is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default how do Bitsets work?

    i have looked at an example for Bitsets in here : Java - The BitSet Class
    but the output doesn't seem to do anything with logic gates.
    so how exactly do they work?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    BitSets are more stupid than gates: they're just a set of bits where each bit has an index (as with arrays) and a value, 0 or 1. The class allows you to manipulate the bits in several ways, that's all.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    outsorts is offline Member
    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Default Re: how do Bitsets work?

    they don't look useful at all for me , but just for knowledge could you give me an example of what happens in an "and operation" with 2 BitSets?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    They can be quite useful: I use bit sets for a list of SMS messages (coming from home alarm units); every message has an index number; a bit set represents all present messages at a certain time T_i; if at time T_i+1 the (new) bit set has one or more bits set to 1, not present in the set for time T_i, I know that new messages have arrived from the home alarm units ... I use the andNot( ... ) method for this purpose.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: how do Bitsets work?

    Quote Originally Posted by JosAH View Post
    They can be quite useful: I use bit sets for a list of SMS messages (coming from home alarm units); every message has an index number; a bit set represents all present messages at a certain time T_i; if at time T_i+1 the (new) bit set has one or more bits set to 1, not present in the set for time T_i, I know that new messages have arrived from the home alarm units ... I use the andNot( ... ) method for this purpose.
    Very clever. I'd just use a previous and a current integer counter to be honest ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by gimbal2 View Post
    Very clever. I'd just use a previous and a current integer counter to be honest ;)
    That doesn't work: those SMS messages get an index number; if the latest 10 message were, say, 1, 2, 3, 4 ... 10 but now the 10 latest messages are 6, 7, 8, 9 ... 15, those bit sets tell me that 11, 12, 13, 14, 15 are the new messages ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: how do Bitsets work?

    Ah okay, I missed the part where you know exactly which messages are new :) Indeed my solution would only tell you that there are new ones and then you still have to find them.

    VERY clever.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,944
    Rep Power
    19

    Default Re: how do Bitsets work?

    Quote Originally Posted by gimbal2 View Post
    VERY clever.
    Oh don't.
    He can barely get through the door with his ego as it is!
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: how do Bitsets work?

    Quote Originally Posted by Tolls View Post
    Oh don't.
    He can barely get through the door with his ego as it is!
    I like to see him struggle and kick as he tries though.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by gimbal2 View Post
    Ah okay, I missed the part where you know exactly which messages are new :) Indeed my solution would only tell you that there are new ones and then you still have to find them.

    VERY clever.
    Think of the chip that receives those SMS messages as the core of a cell phone: it assigns pseudo random index values to each received message (it's the index in a small array in the memory of the SIM chip).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by Tolls View Post
    Oh don't.
    He can barely get through the door with his ego as it is!
    Gimbal is a nice guy and you are note; so there :-P

    *grmbl*

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by gimbal2 View Post
    I like to see him struggle and kick as he tries though.
    You and Tolls are not nice to me anymore; mommy!

    *grmbl*

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: how do Bitsets work?

    There you go, now you're all caught up with the thread :p

    I'm your friendly neighborhood ahole! F you in the A, and have a nice day!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by gimbal2 View Post
    There you go, now you're all caught up with the thread :p

    I'm your friendly neighborhood ahole! F you in the A, and have a nice day!
    My finger is dangling above the rotating knives machine button ...

    <diabolical laughter/>

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: how do Bitsets work?

    To do what? Cut an apple?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #16
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,944
    Rep Power
    19

    Default Re: how do Bitsets work?

    Quote Originally Posted by JosAH View Post
    My finger is dangling above the rotating knives machine button ...

    <diabolical laughter/>

    Jos
    <imp-on-shoulder>do it...Do It...DO IT!</imp-on-shoulder>
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  17. #17
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: how do Bitsets work?

    It's amazing how this forum leads one to learn. I knew how BitSet was implemented and could either be a single primitive or an array of primitives depending on the size of the bit set. But when I was looking at the code, it still did a bit shift of the specified index, without scaling, regardless of the index size. Here's the set method from the BitSet class:
    Java Code:
    public void set(int bitIndex) {
            if (bitIndex < 0)
                throw new IndexOutOfBoundsException("bitIndex < 0: " + bitIndex);
    
            int wordIndex = wordIndex(bitIndex);
            expandTo(wordIndex);
    
            words[wordIndex] |= (1L << bitIndex); // Restores invariants
    
            checkInvariants();
        }
    After plowing thru my books (including a Sun published SCJP guide), I had to check out the language spec to find out that only the 5 or 6 low order bits (depending on int vs long conversion) are used in the shift distances. I could not find this in my books nor in the tutorials. Ref: Chapter*15.*Expressions.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  18. #18
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by gimbal2 View Post
    To do what? Cut an apple?
    This exlplains it all in detail: Monty Python- Architect Sketch - YouTube

    kindest regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  19. #19
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: how do Bitsets work?

    Quote Originally Posted by jim829 View Post
    It's amazing how this forum leads one to learn. I knew how BitSet was implemented and could either be a single primitive or an array of primitives depending on the size of the bit set. But when I was looking at the code, it still did a bit shift of the specified index, without scaling, regardless of the index size. Here's the set method from the BitSet class:
    Java Code:
    public void set(int bitIndex) {
            if (bitIndex < 0)
                throw new IndexOutOfBoundsException("bitIndex < 0: " + bitIndex);
    
            int wordIndex = wordIndex(bitIndex);
            expandTo(wordIndex);
    
            words[wordIndex] |= (1L << bitIndex); // Restores invariants
    
            checkInvariants();
        }
    After plowing thru my books (including a Sun published SCJP guide), I had to check out the language spec to find out that only the 5 or 6 low order bits (depending on int vs long conversion) are used in the shift distances. I could not find this in my books nor in the tutorials. Ref: Chapter*15.*Expressions.
    It's defined in the JLS (see paragraph 15.19).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  20. #20
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,869
    Rep Power
    5

    Default Re: how do Bitsets work?

    Quote Originally Posted by jim829 View Post
    It's amazing how this forum leads one to learn.
    That's because it is visited by extremely cool, intelligent and inspiring people like JosAH.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Page 1 of 2 12 LastLast

Similar Threads

  1. I can't get jar to work on the CLI
    By Mr Wogan in forum New To Java
    Replies: 4
    Last Post: 12-21-2012, 12:51 PM
  2. Replies: 2
    Last Post: 11-25-2012, 02:51 AM
  3. applet call dll work in Win2000 but not work in WinXP
    By manhcuongtin4 in forum Java Applets
    Replies: 1
    Last Post: 07-14-2011, 01:45 PM
  4. how would i get this to work...?
    By deeadeed in forum New To Java
    Replies: 6
    Last Post: 12-06-2007, 02:58 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •