On 23/04/17 15:13, nacho wrote:
> Hello,
> This could sound like a dumb question, it may be.
> If I print:
> 8r3 * 8r3 I get 9.
> It seems that Pharo converts first to decimal and then performs the
> multiplication. How do I get the result in octal which should be 8r11?
> Thanks!
> 

Hi Nacho

There is no such thing as an "octal multiplication".

Smalltalk has a notion of numerical literals, like 28, 10r28, 8r34 or
16r1C. They all represent the same number, namely the abstract notion of
twenty-eight. But it not correct to say that Smalltalk first converts to
decimal. The internal representation of an integer value in Smalltalk
is, in fact, binary, but this should be mostly transparent to most
usages. Smalltalk code does not care whether twenty-eight appears as
octal or whatever in source code.

Something similar holds in C, C++, Java, Lisp, Python, Haskell or any
other of thousands of programming languages out there. If you are used
to one of these, you should not be surprised by the behavior of Smalltalk.

When a numerical result is printed, it is usually written as decimal
number by default (in Smalltalk as well as in many other languages). As
Peter points out, you must be explicit if you need a different
representation.

Greetings
Raffaello

Reply via email to