Public classMain { Public Static voidMain (String []args) {Main main=NewMain (); System.out.println ("Main:" +Main. Hex (j)); System.out.println ("Sys:" +integer.tohexstring (j)); } PrivateString Hex (inti) {string string=""; String Temp=integer.tobinarystring (i); intLen =temp.length (); SYSTEM.OUT.PRINTLN (temp); System.out.println (len); while(len%4!=0) {Temp= "0" +temp; Len=temp.length (); } while(len>0) { //System.out.println (len+ "" +string); intbit = 0; if(Temp.charat (len-1) = = ' 1 ') {bit+=1; } if(Temp.charat (len-2) = = ' 1 ') {bit+=2; } if(Temp.charat (len-3) = = ' 1 ') {bit+=4; } if(Temp.charat (len-4) = = ' 1 ') {bit+=8; } Switch(bit) { Case10: String= ' A ' +string; Break; Case11: String= ' B ' +string; Break; Case12: String= ' C ' +string; Break; Case13: String= ' D ' +string; Break; Case14: String= ' E ' +string; Break; Case15: String= ' F ' +string; Break; default: String=bit+string; Break; } Len-=4; } returnstring; }}
Java by shift 16 binary