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.