I'm currently trying to complete a hw assignment and honestly confused how to even get past this point.
I am supposed to ask the user for a bit string length of 24 that consists of 1's and 0's. I just can't seem to understand how I would go filling up each single array slot with a only 1 value. After I am giving the 24 bit string of 1's and 0's I'm suppose to convert that 24 bit string into 3 separate 8 bit integer components that represent a number from 0-255, which is suppose have a value on the RGB scale.
For example I would take in a bit string of "111111110000000000000000" this would represent "111111111" for red which would be 255, "00000000" for green which would be 0 and "00000000" for blue, so this value would represent pure red.
I'm very stuck on what to do to even start this but I would think its something like this
import java.util.Scanner;
public class Test {
public static void main(String args[]){
String[] bitString;
bitString = new String[24];
Scanner consuleInput = new Scanner(System.in);
System.out.println("what is your input bit string?");
for(int i=0;i < bitstring.length; i++) {
bitString = consuleInput.nextLine();
// this was my rough idea on how to go through the array at everyone spot
// and fill in a 0 or 1 depending on what the giving bitString is
}
When it comes to splitting the bit string into three components i'm honestly not sure. I would think its something like you take the bit string array of [0] to[7] and assign that to the redValue, [8]-[15] to green and [16]-[23] to blue. with these three split up I would use something like
int re = Integer.parseInt(redValue, 2);
which would give me the integer value of that string of 1's and 0's from bitString[0] to bitString[7]. I'm just not entirely sure how to implement it.