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.
私は以下のようなコードを持っています:
x = readsomevalue(); print x
出力される値は整数です。これを16進数にしたいのですが、
返される整数 (x) には、先頭に 0 が含まれています (例: 0543676)。このため、標準的な方法は失敗します
x.to_s(16) = 0
これを解決するには?何人かが重複としてマークしているので、先頭に 0 があると標準呼び出しが失敗するので、先頭の 0 を削除する方法はありますか?
Fixnum#to_s
255.to_s(16) # => "ff"
Kernel#format:
'%x' % 255 # => "ff"