Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8974059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:35:42+00:00 2026-06-15T18:35:42+00:00

What is wrong with my compact boolean array implementation? It is not working. The

  • 0

What is wrong with my compact boolean array implementation? It is not working. The tests are failing so I am doing some bitwise operation incorrectly. 🙁

public class CompactBooleanArray {

    private final int size;
    private final long[] bitmap;

    public CompactBooleanArray(int size) {
        this.size = size;
        int numberOfLongs = (size + 63) / 64;
        bitmap = new long[numberOfLongs];
    }

    public final void set(int index, boolean value) {
        int longIndex = index >> 6;
        int bitPosition = index & 63;

        if (value) {
            bitmap[longIndex] |= (1 << bitPosition);
        } else {
            bitmap[longIndex] &= ~(1 << bitPosition);
        }
    }

    public final boolean get(int index) {
        int longIndex = index >> 6;
        int bitPosition = index & 63;

        return (bitmap[longIndex] & (1 << bitPosition)) != 0;

    }

    public final int length() {
        return size;
    }
}

My failing test:

public class CompactBooleanArrayTest {

    @Test
    public void testSimple() {

        int[] x = { 4, 56, 60 };

        CompactBooleanArray array = new CompactBooleanArray(100);

        for(int i : x) array.set(i, true);

        for(int i = 0; i < array.length(); i++) {
            System.out.println("I: " + i + " -> " + array.get(i));
            if (check(i, x)) {
                Assert.assertTrue(array.get(i));
            } else {
                Assert.assertFalse(array.get(i));
            }
        }
    }

    private boolean check(int value, int[] array) {
        for(int i : array) {
            if (value == i) return true;
        }
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:35:43+00:00Added an answer on June 15, 2026 at 6:35 pm

    Without trying it, I’d say your shifts of 1 << bitPosition, etc. are failing because you’re not using 1L. i.e. 1 << 50 = 0, 1L << 50 = 2^50th

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats wrong with my query? ALTER TABLE test_posts ADD sticky boolean NOT NULL default
Compact description I'm having a problem to find out what's wrong, for some obscure
Working in .NET Compact Framework, C#, .Net 3.5, Visual Studio 2008. Targeting Windows Mobile
I've started working on some Project Euler problems, and have solved number 4 with
I am working with a SQL compact database and I am able to test
I'm neither good nor experienced about asking questions so i hope I'm not doing
Here is some sample code of how I am creating/connecting/working with my database string
I am using a SQL Server Compact database for a project I am working
in wrong i remove the path from my computer, now the path is empty
What wrong with this validation: Jquery: $(document).ready(function(){ $(#addcmd).attr(disabled,disabled); $(#cmdstxt).keypress( function(event){ var txt=$(#cmdstxt); if( txt.val().length

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.