If Statement Help

java

#1

So, I'm doing Java and I put in this If statement, no else yet, but for some reason it says the error is "incomparable types: Int and String." Why is this? How do I fix it? Here is my code:

public static void main(String[] args)
{
int binaryDigitIndex = 7, //Used to cycle one index at a time through inputted Binary String in reverse order.
hexLoopCounter = 0, //Used to cycle through inputted Binary String in groups of 4.
decimalNumber = 0, //The Binary String converted into a decimal value
binaryDigitValue = 0, //Binary character digit converted to integer
powerFactorForPosition = 0, //Power of 2 factor for position to convert Binary To Decimal. 2 to the power of 0 through 2 to the power of 7.
hexSubstringIndex = 0; //
char binaryDigitChar = ' '; //Single character extracted from inputted Binary String.
Scanner input = new Scanner(System.in); //Scanner object for obtaining input from the keyboard.
String binaryString = "", //The Binary String input by the user.
hexadecimalNumberString = "", //The Binary String converted to a hexidecimal String.
hexDigitString="", //A 4 character Binary Substring converted to a single hexadecimal value as a String.
binarySubstring; //4 character group Substring of the inputted Binary String.

   
   System.out.println("Enter an 8 digit binary number and press Enter:");
   binaryString = input.nextLine();
   System.out.println("");


    if (binaryString != 8) { //this line is where the error is
       System.out.println("Error: Must be 8");

#2

Well binaryString is a string and 8 is an integer so the types are incomparible but the compiler already told you this. Maybe use Integer.parseInt(binaryString,2) or Integer.parseInt(binaryString,10) to make it a base 2 or base 10 integer.


#3

Oh! I didn't know that lol. I had no idea what it was talking about when it said Int and string lol. Thanks.


#4

What does making it a base 2 or base 10 integer mean exactly?


#5

As far as I remember it works like this:

Integer.parseInt("111",2) would read that string number as base 2 and turn it into an integer number so in this case

1*2^2+1*2^1+1*2^0 = 4+2+1=7

whereas Integer.parseInt("111",10) would interpret it as 111.