From: Konrad Meyer Date: 2007-10-31T11:04:53+09:00 Subject: Re: (BitTorrent-related) binary "string" to hexadecimal? --nextPart1419135.RkJO9yV2Cq Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Shanti Braford: > Ok in case anyone is curious, this seems to work... >=20 > digest_hex =3D digest.unpack('H*') > # =3D> "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" >=20 > http://www.ruby-doc.org/core/classes/String.html#M000775 >=20 > I still have no clue what a "hex nibble" is but it does the trick in a=20 > pinch! =3D) Each character in a string from SHA1.digest() is single byte ranging from= 0=20 to 255. What you want to do is take each byte, and break it into the most=20 significant 4 bits and the least significant 4 bits, and represent each of= =20 these as a hex nibble. Hence, your "0beece..." string will be twice as long= ,=20 but has the benefit of being human readable (or matching the protocol :D). #unpack("H*") is doing what you want, and I'd say it is *not* just a quic= k=20 hack, but a valid solution to your problem. Good luck and happy rubying. HTH, =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart1419135.RkJO9yV2Cq Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHJ+LDCHB0oCiR2cwRAinFAJwLR/jTe3q1HQBOIe6PorPuITBHKgCgoeSI wJFBCARgc2iAzHuefBXuxC8= =7J93 -----END PGP SIGNATURE----- --nextPart1419135.RkJO9yV2Cq--