mercredi 13 juillet 2016

Calculate and compare int loop?

public class Convertion {

public int PassIN;
public int PassOUT;


public String convertStringToHex(String str){

    char[] chars = str.toCharArray();

    StringBuffer hex = new StringBuffer();
    for(int i = 0; i < chars.length; i++){
    hex.append(Integer.toHexString((int)chars[i]));
    }

    return hex.toString();
}

public void cnvrt(){

  Udp callUdp = new Udp();
   try {
        callUdp.socketp();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
 String trnsferRP = callUdp.trnsfrRPckt();

 Convertion strToHex = new Convertion ();
 String hex = strToHex.convertStringToHex(trnsferRP);
 String cut = hex.substring(10);

 String A = cut.substring(0, 2);
 String B = cut.substring(2, 4);
 String C = cut.substring(4, 6);
 String D = cut.substring(6, 8);

 int cvA = Integer.parseInt(A);
 int cvB = Integer.parseInt(B);
 int cvC = Integer.parseInt(C);
 int cvD = Integer.parseInt(D);

 int calcA = (cvA - 30) * 16;
 int calcB = (cvB - 30);
 int calcC = (cvC - 30) * 16;
 int calcD = (cvD - 30);

 this.PassIN = calcA + calcB;
 this.PassOUT = calcC + calcD;

 int tempIN = 0;
 int tempOUT = 0;
 int LPassIN;
 int LPassOUT;

 if (tempIN == 0){
     LPassIN = PassIN + tempIN;
     System.out.println(LPassIN);
 }else if (LPassIN != PassIN){
     LPassIN = PassIN;
     System.out.println(PassIN);
 }else{
     System.out.println(LPassIN);
 }

 if (tempOUT == 0){
     LPassOUT = PassOUT + tempOUT;
     System.out.println(LPassOUT);
 }else if (LPassOUT != PassOUT){
     System.out.println(PassOUT);
 }else{
     System.out.println(LPassOUT);
  }

 }


public int donecnvrtin(){
    return this.PassIN;
}

public int donecnvrtout(){
    return this.PassOUT;
 }

}

I'm trying to compare calculated PassIN with LPassIN, so I start with a loop by passing O into LPassIn ,then LPassIN will hold a new first int from PassIN.After that if a new second int come,the variable will compare both int LPassIn and PassIN.If different then print PassIN then save/hold the into LPassIN,if same then just print LPassIN.

So if a new third int come,it will be compare to the new second int

is my method wrong or there's a rule to setup this?

*ignore the PassOUT

Aucun commentaire:

Enregistrer un commentaire