BasicFunctions { public static short norm(int var1) throws ArithmeticException { if(var1==0) throw new ArithmeticException("Value can not be 0"); int currValue=var1; if(var1<0) { if(var1<=0xC0000000) return 0; currValue=~(var1-1); } short count=-1; if(currValue>>16!=0) currValue=currValue>>16; else count+=16; if(currValue>>8!=0) currValue=currValue>>8; else count+=8; if(currValue>>4!=0) currValue=currValue>>4; else count+=4; if(currValue>>2!=0) currValue=currValue>>2; else count+=2; if(currValue>>1==0) count+=1; return count; } BasicFunctions(); static short checkOverflow(int value); static int checkIntOverflow(long value); static short add(short var1,short var2); static short sub(short var1,short var2); static short mult(short var1,short var2); static short mult_r(short var1,short var2); static short abs(short var1); static short div(short var1,short var2); static int L_mult(short var1,short var2); static int L_add(int var1,int var2); static int L_sub(int var1,int var2); static short norm(int var1); static final short A; static final short B; static final short MIC; static final short MAC; static final short INVA; static final short DLB; static final short QLB; static final short H; static final short NRFAC; static final short FAC; }
@Test public void testNorm() { assertEquals(0, BasicFunctions.norm(0x40000000)); assertEquals(8, BasicFunctions.norm(0x00400000)); assertEquals(17, BasicFunctions.norm(0x00002000)); assertEquals(26, BasicFunctions.norm(0x00000010)); assertEquals(2, BasicFunctions.norm(0xF0000000)); assertEquals(7, BasicFunctions.norm(0xFF800000)); assertEquals(16, BasicFunctions.norm(0xFFFFC000)); assertEquals(25, BasicFunctions.norm(0xFFFFFFE0)); }