[Pharo-project] Another stupid question
Hi guys, I know it sounds stupid but how do I convert numbers from one base to another ? I found 3 printStringBase: 2 -> '11' But I would like something like 11 convertFromBase: 2 to: 10 -> 3 The Finder did help me about this one so I ask here :) Thanks in advance, Ben
Hi Ben, use that: 2r11 printStringBase: 10 -> 3 16r11 printStringBase: 10 ->17 Cheers, Jannik On Feb 14, 2013, at 10:05 PM, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
Hi guys, I know it sounds stupid but how do I convert numbers from one base to another ?
I found
3 printStringBase: 2 -> '11'
But I would like something like
11 convertFromBase: 2 to: 10 -> 3
The Finder did help me about this one so I ask here :)
Thanks in advance,
Ben
On 14 Feb 2013, at 22:05, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
Hi guys, I know it sounds stupid but how do I convert numbers from one base to another ?
I found
3 printStringBase: 2 -> '11'
But I would like something like
11 convertFromBase: 2 to: 10 -> 3
The Finder did help me about this one so I ask here :)
Thanks in advance,
Ben
It is not the number itself that is in some base, but its representation. So you have to convert from one string representation to another. So something like this should work: (Integer readFrom: 'FF' base: 16) printStringBase: 2 Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
participants (3)
-
Benjamin -
jannik.laval -
Sven Van Caekenberghe