Results 1 to 2 of 2
  1. #1
    JavaRosie is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default BitCount() Issue

    Perhaps I'm misunderstanding the purpose of BitCount. I thought that it would return the number of bits needed to represent the current value held in a variable. Is this correct?

    I'm trying to write a simulator but certain registers can't be over 24 bits or 48 bits. Hm, well, closest I have to that are Integers and Longs.

    Here's the function checking:

    Java Code:
    	public void SetValue(long val){
    		
    		System.out.println(" bitCount: " + Long.bitCount(val));
    		
    		if(Long.bitCount(val) > bitNum){
    			System.out.println("Too many bits! bitCount: " + Long.bitCount(val) + " > " + bitNum);
    		}
    		else{
    			value = val;
    		}
    	}
    And here's my output:
    Java Code:
    //In the test program I set the initial value to 3. The max number of bits
    //is also 3, for testing simplicity.
    
    bitCount: 2
    Reg Value: 3
    
    Input really big number: 
    25
    
    bitCount: 3
    Reg Value: 25
    Nevermind--I found my answer elsewhere.
    Last edited by JavaRosie; 09-20-2010 at 01:52 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    So that, it's better to post your solution over here. It may helpful for others as well. And also if you've solve the problem then please mark the thread solved.

Similar Threads

  1. Having an issue with this
    By baap30 in forum New To Java
    Replies: 5
    Last Post: 04-23-2010, 06:32 AM
  2. JSF issue
    By premjo in forum New To Java
    Replies: 0
    Last Post: 02-14-2010, 03:19 PM
  3. Issue
    By FlashNinja in forum New To Java
    Replies: 20
    Last Post: 11-28-2009, 10:44 PM
  4. PDF Box issue
    By jazz2k8 in forum Advanced Java
    Replies: 0
    Last Post: 03-20-2009, 12:04 PM
  5. Issue
    By chaitu444 in forum New To Java
    Replies: 2
    Last Post: 11-06-2007, 08:49 PM

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
  •