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 
    {
     BufferedReader in = new BufferedReader(new FileReader
        ("C:\\Documents and Settings\\guest987 
        \\Desktop\\ce\\bgptable2.txt"));
     try 
       {
           String input;
           while((input=in.readLine())!=null)
               {
	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;
		      }
	                //ASSIGN ADDRESSES TO PREFIX LEVELS
                                long address = ip;
	                long mask = x;
		String cat = Long.toBinaryString(address); 
		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 
    {
     BufferedReader in = new BufferedReader(new FileReader
        ("C:\\Documents and Settings\\guest987 
        \\Desktop\\ce\\bgptable2.txt"));
     try 
       {
           String input;
           while((input=in.readLine())!=null)
               {
	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;
		      }
	                //ASSIGN ADDRESSES TO PREFIX LEVELS
                                long address = ip;
	                long mask = x;
		String cat = Long.toBinaryString(address); 
		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?

commented: Please pay attention to other posts in the thread. -2

See the post above yours.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.