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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:37:43+00:00 2026-05-23T01:37:43+00:00

So I have this assignment to simulate allocating data. It goes like this its

  • 0

So I have this assignment to simulate allocating data. It goes like this

its an int[] array whose elements in binary make up the allocation table like:

int[0] = 0xFF = 1111 1111;

1 is said to be free and 0 is allocated

if you call the get() method (also get(int) where int is the number of bits to be allocated), then it finds the first chunk of “free” space and changes the value to 0. free() (free(int numbits) or free(int numbits, int fromIndex)) changes the bits back to 1. examples:

data == 1111 0011
x.get(3);
data == 0001 0011
x.get(2);
data == 0001 0000
x.get();
data == 0000 0000
x.free(2);
data == 1100 0000
x.free(2, 5);
data == 1100 0110

All the elements in the int array get pushed together so if theres 2 elements, the binary representation would be 16 1 bits. The allocation has to be able to happen accross all the elements in the array.

How can I accomplish this using the bitwise operators and the Integer.toBinaryString() method.
This is an assignment so Id like there to be more advice than actual answers. Hopefully i explained it well enough.

  • 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-05-23T01:37:44+00:00Added an answer on May 23, 2026 at 1:37 am

    Two useful functions that I have in my toolkit for binary ops are given below.

    boolean isSet(int value, int bit){
       return (value&(1<<bit))!=0;
    }  
    
    int setBit(int value, int bit){
       return value|(1<<bit);
    }
    

    Basically you check whether a given bit is set by AND-ing it with another int which has all zeros and only the bit you are interested in set. The resulting value has zeros in every bit but will have that bit set only if it was set in the original value. Otherwise that bit is 0 (since 0 AND 1 is 0) making the whole result 0. Having a non-zero result means the bit was set.

    To set a bit you just OR it with a value that has zeros in every bit and a 1 in the bit which you want to set. This gives a result which has all the other bits the same as they were in the original value but a 1 in the bit which you want to set.

    Using this you can treat any int much like a size 32 boolean array and set or unset bits at any position.

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

Sidebar

Related Questions

I am doing this assignment, make a program that solves sudoku. I have a
I have declared my array like this: FT_Interface<4096> *to_make_ft[3] = { /* initialization with
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
This is one of the tasks of my assignment. I have a Turing machine
I have this assignment due that requires the usage of FLTK. The code is
I have this assignment that I've tried. But when I enter 1 it should
I have this programming assignment that converts between meters and feet, and between kilograms
I'm doing another Java project for my class. In this assignment, we have to
Hallo I have this assignment to print only alphabets in a C++ string. It
So I have this assignment where I read in 1 line at a time

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.