為什么我全部都加了0
public?static?void?printHexByByteArray(String?fileName)?throws?IOException{ ????FileInputStream?in?=?new?FileInputStream(fileName); ????????byte[]?buf?=?new?byte[20?*?1024]; ????int?bytes?=?in.read(buf,0,buf.length);//一次性讀完,說(shuō)明字節(jié)數(shù)組足夠大 ????int?j?=?1;???//定義一個(gè)j來(lái)計(jì)數(shù) ????//i?<?bytes???因?yàn)闆](méi)有讀到最后,所以是這樣寫 ????for?(int?i?=?0;?i?<?bytes;?i++)?{ ????????if?(buf[i]?<=?0xf)?{??//個(gè)位數(shù)補(bǔ)0 ????????????System.out.print("0"); ????????} ????????System.out.print(Integer.toHexString(buf[i]?&?0xff)+"??"); ????????if?(j++?%?10?==?0)?{??//每輸出10個(gè)byte換行 ????????????System.out.println(); ????????} ????}
輸出結(jié)果所有的都加了0,而不是只有一位數(shù)的才加0,為什么
2018-11-30
數(shù)組中有負(fù)數(shù),所有必須避免負(fù)數(shù)