On 15.02.2013 11:29, Benjamin wrote:
On Feb 15, 2013, at 11:24 AM, Sven Van Caekenberghe <s...@stfx.eu> wrote:
On 15 Feb 2013, at 11:11, Henrik Johansen <henrik.s.johan...@veloxit.no> wrote:
On Feb 15, 2013, at 1:51 AM, Benjamin wrote:
On Feb 15, 2013, at 1:40 AM, "Torsten Bergmann" <asta...@gmx.de> wrote:
This was just an example to play with since you asked
for a #convertFromBase:to: method in your original mail
and one cant provide such a method on Number. Your
original request
11 convertFromBase: 2 to: 10
may work - but it wont work for hex values:
FF convertFromBase: 16 to: 10
then FF would have to be a string.
'FF' convertFromBase: 16 to: 10
So having a #convertFromBase:to: on String is not to recommend
(especially since the string has to be in a number format)
and also not necessary. I should have added this to my mail
as a warning.
Just use
(Number readFrom: self base: sourceBase) printStringBase: targetBase
Thank you
If necessary put it in a private helper method for conversion.
May I ask why you require conversions between the different base systems?
I have to implement a FTP server for a lecture, and the port is provided in a
strange format (twice 8 bits).
So I needed to change the port in base 10 to base 2, cut it into two pieces,
then turn those pieces back in base 10 :)
Working on a hex editor for Nautilus? ;)
Is a hex editor a need ? :)
Ben
Bye
T.
Wait, wait, wait.
You mean like #[16 45] ?
What's wrong with
Number1 := sourceNumber >> 8
Number2 := sourceNumber bitAnd: 255
?
Cheers,
Henry
There is also
sourceNumber asByteArrayOfSize: 2
1000 asByteArrayOfSize:2 #[3 232]
Thank you guys :)
I definitely feel stupid now :D
Ben
http://www.catb.org/esr/faqs/smart-questions.html#idp29958640http://www.catb.org/esr/faqs/smart-questions.html#idp29958640
;)
Cheers,
Henry