[Pharo-project] Another stupid question
Add this method to String class: convertFromBase: sourceBase to: targetBase "Convert the receiver (who has to represent a number string) from the given source base to the given target base 'FFFF' convertFromBase: 16 to: 2 " ^(sourceBase asString,'r', self) asNumber printStringBase: targetBase And then try: 'FFFF' convertFromBase: 16 to: 10 'FFFF' convertFromBase: 16 to: 2 '11111110' convertFromBase: 2 to: 16 ... Have fun Torsten
On 15 Feb 2013, at 00:09, "Torsten Bergmann" <astares@gmx.de> wrote:
convertFromBase: sourceBase to: targetBase "Convert the receiver (who has to represent a number string) from the given source base to the given target base
'FFFF' convertFromBase: 16 to: 2 " ^(sourceBase asString,'r', self) asNumber printStringBase: targetBase
Please, make that ^ (Number readFrom: self base: sourceBase) printStringBase: targetBase No useless copying and concatenating, simpler and more elegant. Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
so could you write two tests and submit a slice so that we improve the system Stef
convertFromBase: sourceBase to: targetBase "Convert the receiver (who has to represent a number string) from the given source base to the given target base
'FFFF' convertFromBase: 16 to: 2 " ^(sourceBase asString,'r', self) asNumber printStringBase: targetBase
Please, make that
^ (Number readFrom: self base: sourceBase) printStringBase: targetBase
No useless copying and concatenating, simpler and more elegant.
Sven
-- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
participants (3)
-
stephane ducasse -
Sven Van Caekenberghe -
Torsten Bergmann