Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class IEE {
- private int shift = 0;
- private String exponenta = "";
- private char sign;
- public String getmRes() {
- return mRes;
- }
- private String mRes = "";
- public Result getAndroidResult() {
- return androidResult;
- }
- private Result androidResult = new Result();
- private String move(String inp){
- if(inp.charAt(0)=='1' && (inp.charAt(1)==',' || inp.charAt(1)=='.')){
- this.shift=0;
- return inp;
- }
- inp = inp.replace(',','.');
- String result = "";
- if(inp.charAt(0)=='0'){
- int pos = inp.indexOf('1');
- this.shift = -(pos-1);
- for(int j=pos+1;j<inp.length();j++){
- result+=inp.charAt(j);
- }
- if(result.length()<23){
- for(int j=result.length();j<23;j++){
- result+="0";
- }
- }
- return result;
- }
- if(inp.charAt(0)=='1'){
- int pos = inp.indexOf('.');
- this.shift=pos-1;
- result=inp.replace(".","");
- result=result.substring(1);
- if(result.length()<23){
- for(int j=result.length();j<23;j++){
- result+="0";
- }
- }
- return result;
- }
- return result;
- }
- private void calcExponenta(){
- Calc calc = new Calc();
- calc.setFrom(10);
- calc.setTo(2);
- int ex = 127+this.shift;
- calc.mExchange(Integer.toString(ex));
- String res = calc.getResult();
- if(res.length()<8){
- for(int i=res.length();i<8;i++){
- res = "0"+res;
- }
- }
- this.exponenta = res;
- }
- private void exploreSign(String inp){
- if(inp.charAt(0)=='-'){
- this.sign = '1';
- this.androidResult.addLine("Liczba ujemna wiec bit znaku to 1", Text.textStyle.DESCRIPTION);
- }else{
- this.sign='0';
- this.androidResult.addLine("Liczba dodatnia wiec bit znaku to 0", Text.textStyle.DESCRIPTION);
- }
- }
- public void letsIEE(String input){
- this.androidResult = new Result();
- this.androidResult.addLine("Dane wejsciowe: "+input, Text.textStyle.NORMAL);
- this.exploreSign(input);
- if(input.charAt(0)=='+' || input.charAt(0)=='-'){
- input = input.substring(1);
- }
- Calc calc = new Calc();
- calc.setFrom(10);
- calc.setTo(2);
- calc.mExchange(input);
- this.androidResult.addLine("Zamieniamy liczbe na binarna: "+calc.getResult(), Text.textStyle.DESCRIPTION);
- String movRes = this.move(calc.getResult());
- this.androidResult.addLine("Przesuwamy przecinek tak, aby po lewej stronie była pojedyncza jedynka", Text.textStyle.DESCRIPTION);
- this.androidResult.addLine("Przesuniecie to: "+this.shift, Text.textStyle.DESCRIPTION );
- this.androidResult.addLine("Wszystko po prawej stronie przecinka kodujemy na 23 bitach: "+movRes, Text.textStyle.DESCRIPTION);
- this.calcExponenta();
- this.androidResult.addLine("Do przesuniecia dodajemy bias(127) i kodujemy go binarnie na 8 bitach: " + this.exponenta, Text.textStyle.DESCRIPTION);
- this.mRes = this.sign +" "+ this.exponenta+" " + movRes;
- this.androidResult.addLine("Wynik to: "+this.sign +" "+ this.exponenta+" " + movRes, Text.textStyle.RESULT);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement