请问以下java代码中Integer.toHexString(b&0xff)括号中为什么要写b&0xff,请问有什么作用?表示什么意思?
publicstaticStringtoHexString(byte[]md5){ StringBuilderbuf=new...
public static String toHexString(byte[] md5) { StringBuilder buf = new StringBuilder(); for (byte b : md5) { buf.append(leftPad( Integer.toHexString(b&0xff), '0', 2)); } return buf.toString(); } public static String leftPad( String hex, char c, int size) { char[] cs = new char[size]; Arrays.fill( cs, c); System.arraycopy(hex.toCharArray(), 0, cs, cs.length-hex.length(), hex.length()); return new String(cs); } public static void main(String[] args) { System.out.println(md5("1234")); //81dc9bdb52d04dc20036dbd8313ed055 -> 1234 }
展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询