String>>
isValidBinary
^self allSatisfy: [:each | each = $0 or: [each = $1]]
binaryToDecimal
"The caller should ensure that self isValidBinary before calling this."
^self inject: 0 into: [:acc :each |
acc*2 + (each codePoint - $0 codePoint)]
On Mon, 27 Apr 2020 at 06:05,
On Sun, Apr 26, 2020 at 10:11 AM Roelof Wobben via Pharo-users <
pharo-users@lists.pharo.org> wrote:
> Hello,
>
> I have to make some code that convert a binary to a decimal and im not
> allowed to use the convert methods that Pharo has.
>
> So I have written this :
>
>
> decimalFromBinary:
From:
Pharo-users On
Behalf Of Roelof Wobben via Pharo-users
Sent: 27 April 2020 12:23
To: pharo-users@lists.pharo.org
Cc: Roelof Wobben
Subject: Re: [Pharo-users] mentor question 2
Of Roelof
Wobben via Pharo-users
Sent: 27 April 2020 12:23
To: pharo-users@lists.pharo.org
Cc: Roelof Wobben
Subject: Re: [Pharo-users] mentor question 2.
Op 27-4-2020 om 13:16 schreef PBKResearch:
Roelof
You maybe have enough mentors already, but there are some important features
] mentor question 2.
Op 26-4-2020 om 20:17
schreef Sven Van Caekenberghe:
>
>> On 26 Apr 2020, at 20:10,
Gabriel Cotelli <g.cote...@gmail.com> wrote:
>>
>> In the first method y
.
Peter Kenny
From: Pharo-users On Behalf Of Roelof
Wobben via Pharo-users
Sent: 26 April 2020 19:52
To: pharo-users@lists.pharo.org
Cc: Roelof Wobben
Subject: Re: [Pharo-users] mentor question 2.
Op 26-4-2020 om 20:17 schreef Sven Van Caekenberghe:
>
>> On 26 Apr 2020,
--- Begin Message ---
Op 26-4-2020 om 20:17 schreef Sven Van Caekenberghe:
On 26 Apr 2020, at 20:10, Gabriel Cotelli wrote:
In the first method you aren't doing an assignment, are sending the message =
to the temp isValid, if you change the method to:
decimalFromBinary: aString
|
> On 26 Apr 2020, at 20:10, Gabriel Cotelli wrote:
>
> In the first method you aren't doing an assignment, are sending the message =
> to the temp isValid, if you change the method to:
> decimalFromBinary: aString
> | result isValid |
> isValid := self isValidBinary: aString.
>
In the first method you aren't doing an assignment, are sending the message
= to the temp isValid, if you change the method to:
decimalFromBinary: aString
| result isValid |
* isValid := self isValidBinary: aString.*
isValid
ifTrue: [ result := 0.
aString
--- Begin Message ---
Hello,
I have to make some code that convert a binary to a decimal and im not
allowed to use the convert methods that Pharo has.
So I have written this :
decimalFromBinary: aString
| result isValid |
isValid = self isValidBinary: aString.
isValid
10 matches
Mail list logo