From: Wayne Scott Date: 2001-05-19T05:41:21+09:00 Subject: [ruby-talk:15380] Re: ruby bugs From: Mathieu Bouchard > Bug report. > > > The expression: > > printf "%x", -42 > > shows: > > ..fd6 > > I assert that it should show: > > -2a > > that is, the same as: > > printf "%s%x", (-42<0) ? "-" : "", (-42).abs > > matju printf specifies that the 'x' format is unsigned and Ruby has arbitrary precision integers. So the real value is: fffffffffffffd6 (but with many more 'f's) Ruby just adds '..f' to show that the f's go on forever. Normally you add a field width to show the number of bits you want in the output. sprintf "%.8x", -42 => "ffffffd6" -Wayne