I've not programmed extensively, and I've got to create a program that's beyond my knowledge. I'm trying to create a program that will help me measure the amount of memory a certain IP routing algorithm will use to store address prefixes. The program must convert each dotted decimal address to binary, and then classify the address as having an 8b, 16b, 24b, or 32b prefix-- if a prefix is 7b, it must be extended to 8b; If an address is 9b, it's extended to 16b, etc.

Therefore, I'm checking the 9th, 17th, etc bits in order to see how the address should be categorized. If it has both 1s and 0s in that spot (signifying that more bits are necessary for accurate representation), the program should put the address into the higher category.

Of course, I'm getting caught up in an error-- "incompatible types." Grr >:B

Here's my code:

``````import java.io.*;

public class conversion
{
private static final int maxBytes = 3;
public static void main(String[] args)throws Exception
{
("C:\\Documents and Settings\\guest987
\\Desktop\\ce\\bgptable2.txt"));
try
{
String input;
{
if(input.length()>=3)
{
if(input.length()>=3 && input.substring(0,3).equals("* i"))
{
String bin1 = input.substring(3,input.indexOf(" ",3));
String ips = bin1;
//CONVERT DOTTED IP TO LONG
long ip = 0;
int offset = -1;
int x = 0;
if (ips.indexOf(46, offset+1)!=-1)
{
for(int i=0; i<3; i++)
{
x = Integer.parseInt(ips.substring(offset+1,
ips.indexOf(46, offset+1)));
offset = ips.indexOf(46, offset+1);
ip = ip + x*(long)Math.pow(256,3-i);
}
if (ips.indexOf(47, offset+1) != -1)
{
x = Integer.parseInt(ips.substring(offset+1,
ips.indexOf(47, offset+1)));
offset = ips.indexOf(47, offset+1);
ip = ip + x;
x = Integer.parseInt(ips.substring(offset+1,
ips.length()));
}
else
{
x = Integer.parseInt(ips.substring(offset+1,
ips.length()));
ip = ip + x;
x = 32;
}
String lvl8 = cat.substring(1,9);
String lvl16 = cat.substring(9,17);
String lvl24 = cat.substring(17,25);
int dec8 = lvl8.charAt(9);

if (dec8 = 0)
{				 	                 System.out.println("lol");
}
}
}
}
}
in.close();
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
}

}``````

The error in question is in line 61-- "if (dec8 = 0)". There are likely many more :B Also, the program is not yet complete... I hit the error and haven't gone further. Any help would be tops!

--Courtney

Anyone? :B

Should be `if (dec8 == 0)` .

I've not programmed extensively, and I've got to create a program that's beyond my knowledge. I'm trying to create a program that will help me measure the amount of memory a certain IP routing algorithm will use to store address prefixes. The program must convert each dotted decimal address to binary, and then classify the address as having an 8b, 16b, 24b, or 32b prefix-- if a prefix is 7b, it must be extended to 8b; If an address is 9b, it's extended to 16b, etc.

Therefore, I'm checking the 9th, 17th, etc bits in order to see how the address should be categorized. If it has both 1s and 0s in that spot (signifying that more bits are necessary for accurate representation), the program should put the address into the higher category.

Of course, I'm getting caught up in an error-- "incompatible types." Grr >:B

Here's my code:

``````import java.io.*;

public class conversion
{
private static final int maxBytes = 3;
public static void main(String[] args)throws Exception
{
("C:\\Documents and Settings\\guest987
\\Desktop\\ce\\bgptable2.txt"));
try
{
String input;
{
if(input.length()>=3)
{
if(input.length()>=3 && input.substring(0,3).equals("* i"))
{
String bin1 = input.substring(3,input.indexOf(" ",3));
String ips = bin1;
//CONVERT DOTTED IP TO LONG
long ip = 0;
int offset = -1;
int x = 0;
if (ips.indexOf(46, offset+1)!=-1)
{
for(int i=0; i<3; i++)
{
x = Integer.parseInt(ips.substring(offset+1,
ips.indexOf(46, offset+1)));
offset = ips.indexOf(46, offset+1);
ip = ip + x*(long)Math.pow(256,3-i);
}
if (ips.indexOf(47, offset+1) != -1)
{
x = Integer.parseInt(ips.substring(offset+1,
ips.indexOf(47, offset+1)));
offset = ips.indexOf(47, offset+1);
ip = ip + x;
x = Integer.parseInt(ips.substring(offset+1,
ips.length()));
}
else
{
x = Integer.parseInt(ips.substring(offset+1,
ips.length()));
ip = ip + x;
x = 32;
}
String lvl8 = cat.substring(1,9);
String lvl16 = cat.substring(9,17);
String lvl24 = cat.substring(17,25);
int dec8 = lvl8.charAt(9);

if (dec8 = 0)
{				 	                 System.out.println("lol");
}
}
}
}
}
in.close();
}
catch (IOException e)
{
e.printStackTrace();
System.exit(1);
}
}

}``````

The error in question is in line 61-- "if (dec8 = 0)". There are likely many more :B Also, the program is not yet complete... I hit the error and haven't gone further. Any help would be tops!

hi I am new to java . shall i give my simple solution to sole ur problem.better u change the line if (dec8 = 0) to if (dec8 == 0) then see what happens?