From: Robert Klemme Date: 2004-09-23T19:40:06+09:00 Subject: Re: String#pad ? "Jani Monoses" schrieb im Newsbeitrag news:4152A02D.8090501@iv.ro... > Hello > > is there a nicer way of padding a string to a power of two length than for example Did you mean to say "multiple of two"? 'Cause that's what your code seems to be doing. > data = data.ljust((data.length+3) & ~3) > > this looks too much like C :) :-) Different story but not necessarily nicer: data << (" " * (data.length % 2)) data << (" " * ((data.length + 1) % 2)) If you really meant "power of two" a somewhat weired version: data.ljust( ( "1" + data.length.to_s(2).gsub(/1/, '0') ).to_i( 2 ) ) :-) robert