Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我尝试将 0 到 255 之间的数字转换为十六进制格式。如果我使用sprintf("%X", 1)I get 1,但我需要输出始终具有宽度 2(带前导 0)而不是 1。如何才能做到这一点?
sprintf("%X", 1)
1
使用%02X:
%02X
sprintf("%02X",1) # -> "01" sprintf("%02X",10) # -> "0A" sprintf("%02X",16) # -> "10" sprintf("%02X",255) # -> "FF"