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 8539637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:24:47+00:00 2026-06-11T11:24:47+00:00

If I use a single int to represent an ascii character set, how is

  • 0

If I use a single int to represent an ascii character set, how is using it reducing the storage space by a factor of 8 ? as compared to an array of 256 boolean values ? The single int is also functioning like a bit vector.

A boolean in java will occupy 1 bit as it can represent only true or false values. So for example if i have an array of boolean values. boolean[] char_set = new boolean[256] This will occupy 256 bits correct ? I’m reading that if i use a single int like a bit vector which means I can use 32 bits to cover 256 values. I guess that is reduction by a factor of 8. But why does the code below work ?

It is checking if there are any duplicates in the string. They are assuming an ascii char set. Str is some string.

int checker = 0;
for(int i=0;i<str.length();i++)
{
  int val = str.charAt(i) - 'a';
  if(checker& (1<<val)) > 0)
  {
     return false;
  }
  checker |= (1<<val);
}
  return true;
}

Can someone particularly explain how the bit vector logic works in this case. They are assuming the string contains lowercase characters.

  • 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-11T11:24:49+00:00Added an answer on June 11, 2026 at 11:24 am

    An int is 32 bits, not 256 bits. It alone would not be enough to represent a set of 256 possible items. You need 8 of them. I am not sure what you mean that you can use just 32 bits then.

    It’s not clear what you’re looping over — what is str? All 256 values from 0 to 255? I’m suspicious because you are subtracting 'a'. Is your universe of values only 32 possible chars? Then sure you can use 32 bits. But where did 256 ever come from then?

    Your mask condition needs to be != 0 to work for the highest bit set.

    (A boolean‘s “real” size is opaque to the Java programmer. In reality, you will find that it is not 1 bit (machines aren’t bit-addressable), nor even 1 byte. Java actually uses a whole 32-bit word. But this is not really related to your question.)

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

Sidebar

Related Questions

I want to save an high-score for local use only. A single int, that
How do you use a single character PHP Wildcard to make a String Replacement?
I have been looking at how I could use Single linked lists using the
I try to use single quotes as much as possible and I've noticed that
I want use a single php file to handle all of my voting requests.
Currently I use a single equation with different combination of known/unknown parameters. As I
I want to use a single Doctrine install on our server and serve multiple
I want to use a single font named Algerian across my whole website. So,
If I import and use a single class from another package, will it include
I am trying to use a single RouteURL to route to different pages dependent

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.