2010/12/20 Levente Uzonyi <leves@elte.hu>:
On Mon, 20 Dec 2010, Geoffroy Couprie wrote:
Hello,
2010/12/20 Levente Uzonyi <leves@elte.hu>:
On Mon, 20 Dec 2010, Stéphane Ducasse wrote:
On Dec 19, 2010, at 9:55 PM, Geoffroy Couprie wrote:
Hello all,
I get a strange behaviour while trying to print hexadecimal values of a string.
Context: I get a SHA1 hash from a binary stream, store it into a string, and I want to display that string (using asHex).
Problem: for values inferior to 16, the leading zero is ignored. (15 -> 'F' instead of '0F').
indeed printStringHex prints F instead of 0F 15 printStringHex     'F' 15 hex     '16rF'
Geoffroy could you add a variant that produces the correct behavior with some tests?
No need to do that. As Sven pointed out, he can simply use ByteArray >> #hex. Since his stream is already binary, he can also avoid converting his data to a string.
More context: I am using a ZLibReadStream and its upTo: method, which gives me a ByteString, not a ByteArray. I guess I could convert it to a ByteArray.
But I still think there's a bug here: printing the hex value of a Character should add the leading zero, because they're represented by a full byte.
So, I propose this change:
Character>>hex  ^value printStringBase: 16 nDigits: 2
What about this?
(Character value: 12345) hex
Huh, I forgot multibyte characters... Then would this be sufficient? Character>>hex value >255 ifTrue: [^value hex] ifFalse: [^value printStringBase: 16 nDigits: 2]