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 までの数値を 16 進数形式に変換しようとしています。を使用するsprintf("%X", 1)と が得られます1が、出力の幅は常に 1 ではなく 2 (先頭に 0 を含む) にする必要があります。これはどのように行うことができますか?
sprintf("%X", 1)
1
使用%02X:
%02X
sprintf("%02X",1) # -> "01" sprintf("%02X",10) # -> "0A" sprintf("%02X",16) # -> "10" sprintf("%02X",255) # -> "FF"