Base conversion question..

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Base conversion question..

Rick Flower
Hi all..

I'm toying around with a new toy and need to convert an arbitrary  
character string to
a binary string as shown below to pump into an old algorithm that  
assumes all input
is in a binary string (long story -- if it works I'll update the  
code).. I'm not completely
sure how to do it.. I was toying around in the workspace but didn't  
get any output
with the following code:

foo := 'ABCDEFGHIJ'.
foo2 := foo asInteger
foo2 first printStringRadix: 2

any ideas on how to do this whether with printStringRadix: or otherwise?
The output should look something like :

'0110010101100110' etc..

Thx!

-- Rick
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Boris Popov, DeepCove Labs (SNN)
Re: [vwnc] Base conversion question..

String streamContents: [:ws | 'abc' do: [:char | char asInteger printOn: ws base: 2]]

-Boris (via BlackBerry)

----- Original Message -----
From: [hidden email] <[hidden email]>
To: VWNC NC <[hidden email]>
Sent: Thu Aug 26 00:08:01 2010
Subject: [vwnc] Base conversion question..

Hi all..

I'm toying around with a new toy and need to convert an arbitrary 
character string to
a binary string as shown below to pump into an old algorithm that 
assumes all input
is in a binary string (long story -- if it works I'll update the 
code).. I'm not completely
sure how to do it.. I was toying around in the workspace but didn't 
get any output
with the following code:

foo := 'ABCDEFGHIJ'.
foo2 := foo asInteger
foo2 first printStringRadix: 2

any ideas on how to do this whether with printStringRadix: or otherwise?
The output should look something like :

'0110010101100110' etc..

Thx!

-- Rick
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Andres Valloud-6
In reply to this post by Rick Flower
Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
like this (sort of)?

answer := String new writeStream.
foo := 'ABCDEFGHIJ' asByteArray.
foo do:
        [:eachByte |
                eachByte
                        printOn: answer
                        paddedWith: $0
                        to: 8
                        base: 2
        ].
answer contents

Andres.

On 8/26/2010 12:08 AM, Rick Flower wrote:

> Hi all..
>
> I'm toying around with a new toy and need to convert an arbitrary
> character string to
> a binary string as shown below to pump into an old algorithm that
> assumes all input
> is in a binary string (long story -- if it works I'll update the
> code).. I'm not completely
> sure how to do it.. I was toying around in the workspace but didn't
> get any output
> with the following code:
>
> foo := 'ABCDEFGHIJ'.
> foo2 := foo asInteger
> foo2 first printStringRadix: 2
>
> any ideas on how to do this whether with printStringRadix: or otherwise?
> The output should look something like :
>
> '0110010101100110' etc..
>
> Thx!
>
> -- Rick
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

BREITH Karl-Albert (AREVA)
In reply to this post by Rick Flower
 
| foo foo2 count index |
foo := 'ABCDEFGHIJ'.
count := 1.
index := 1.
foo2 := Array new: (foo size + 3)//4 withAll: 0.
foo do: [:aChar |
        foo2 at: index put: (foo2 at: index) * 256 + aChar asInteger.
        count := count + 1.
      count = 5 ifTrue: [ count := 1. index := index + 1].
].
foo2 first printStringRadix: 2

__________________________________________________________
Karl Breith
AREVA NP GmbH
FDWN-G

Postfach 1109
91001 Erlangen
Phone: +49 (0) 9131 900 95544
Fax: +49 (0) 9131 900 94081
mail to:  [hidden email]
An AREVA and Siemens company
 
Vorsitzender des Aufsichtsrats: Olivier Wantz - Geschäftsführer: Ulrich Gräber, Rüdiger Steuerlein
Sitz der Gesellschaft: Erlangen - Registergericht: Fürth, HRB 7817 - www.areva-np.com - Umsatzsteuer-ID: DE 206407096  
Supervisory Board Chairman: Olivier Wantz - Managing Directors: Ulrich Gräber, Rüdiger Steuerlein
Company Seat: Erlangen - Commercial Registries Fürth, HRB 7817 - www.areva-np.com - VAT ID code: DE 206407096
Wichtiger Hinweis: Diese E-Mail kann Betriebs- oder Geschäftsgeheimnisse bzw. sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtümlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfältigung oder Weitergabe der E-Mail ausdrücklich untersagt. Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen Dank.
Important Note: This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.

-----Ursprüngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Rick Flower
Gesendet: Donnerstag, 26. August 2010 09:08
An: VWNC NC
Betreff: [vwnc] Base conversion question..

Hi all..

I'm toying around with a new toy and need to convert an arbitrary character string to a binary string as shown below to pump into an old algorithm that assumes all input is in a binary string (long story -- if it works I'll update the code).. I'm not completely sure how to do it.. I was toying around in the workspace but didn't get any output with the following code:

foo := 'ABCDEFGHIJ'.
foo2 := foo asInteger
foo2 first printStringRadix: 2

any ideas on how to do this whether with printStringRadix: or otherwise?
The output should look something like :

'0110010101100110' etc..

Thx!

-- Rick
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Boris Popov, DeepCove Labs (SNN)
In reply to this post by Andres Valloud-6
Good point about padding,

String streamContents:
                [:ws |
                'abc' do:
                                [:char |
                                char asInteger
                                        printOn: ws
                                        paddedWith: $0
                                        to: 8
                                        base: 2]]

-Boris

--
DeepCove Labs Ltd.
+1 (604) 689-0322
4th floor, 595 Howe Street
Vancouver, British Columbia
Canada V6C 2T5
http://tinyurl.com/r7uw4

PacNet Services (Europe) Ltd.
+353 (0)61 714-360
Shannon Airport House, SFZ
County Clare, Ireland
http://tinyurl.com/y952amr

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message header.
Unless otherwise indicated, it contains information that is private and
confidential. If you have received it in error, please notify the sender
and delete the entire message including any attachments.

Thank you.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On
Behalf Of Andres Valloud
Sent: 26 August 2010 08:18
To: [hidden email]
Subject: Re: [vwnc] Base conversion question..

Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
like this (sort of)?

answer := String new writeStream.
foo := 'ABCDEFGHIJ' asByteArray.
foo do:
        [:eachByte |
                eachByte
                        printOn: answer
                        paddedWith: $0
                        to: 8
                        base: 2
        ].
answer contents

Andres.

On 8/26/2010 12:08 AM, Rick Flower wrote:
> Hi all..
>
> I'm toying around with a new toy and need to convert an arbitrary
> character string to a binary string as shown below to pump into an old

> algorithm that assumes all input is in a binary string (long story --
> if it works I'll update the code).. I'm not completely sure how to do
> it.. I was toying around in the workspace but didn't get any output
> with the following code:
>
> foo := 'ABCDEFGHIJ'.
> foo2 := foo asInteger
> foo2 first printStringRadix: 2
>
> any ideas on how to do this whether with printStringRadix: or
otherwise?

> The output should look something like :
>
> '0110010101100110' etc..
>
> Thx!
>
> -- Rick
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Steven Kelly
In reply to this post by Rick Flower
#streamContents: isn't in my image - something from Seaside or Squeak?
Presumably something like this:

SequenceableCollection class>>streamContents: unaryBlock
        | ws |
        ws := WriteStream on: (self new: 100).
        unaryBlock value: ws.
        ^ws contents

Steve

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Boris Popov, DeepCove Labs (SNN)
> Sent: 26. elokuuta 2010 12:37
> To: [hidden email]
> Subject: Re: [vwnc] Base conversion question..
>
> Good point about padding,
>
> String streamContents:
> [:ws |
> 'abc' do:
> [:char |
> char asInteger
> printOn: ws
> paddedWith: $0
> to: 8
> base: 2]]
>
> -Boris
>
> --
> DeepCove Labs Ltd.
> +1 (604) 689-0322
> 4th floor, 595 Howe Street
> Vancouver, British Columbia
> Canada V6C 2T5
> http://tinyurl.com/r7uw4
>
> PacNet Services (Europe) Ltd.
> +353 (0)61 714-360
> Shannon Airport House, SFZ
> County Clare, Ireland
> http://tinyurl.com/y952amr
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message
header.
> Unless otherwise indicated, it contains information that is private
and

> confidential. If you have received it in error, please notify the
> sender
> and delete the entire message including any attachments.
>
> Thank you.
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Andres Valloud
> Sent: 26 August 2010 08:18
> To: [hidden email]
> Subject: Re: [vwnc] Base conversion question..
>
> Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
> like this (sort of)?
>
> answer := String new writeStream.
> foo := 'ABCDEFGHIJ' asByteArray.
> foo do:
> [:eachByte |
> eachByte
> printOn: answer
> paddedWith: $0
> to: 8
> base: 2
> ].
> answer contents
>
> Andres.
>
> On 8/26/2010 12:08 AM, Rick Flower wrote:
> > Hi all..
> >
> > I'm toying around with a new toy and need to convert an arbitrary
> > character string to a binary string as shown below to pump into an
> old
>
> > algorithm that assumes all input is in a binary string (long story
--
> > if it works I'll update the code).. I'm not completely sure how to
do

> > it.. I was toying around in the workspace but didn't get any output
> > with the following code:
> >
> > foo := 'ABCDEFGHIJ'.
> > foo2 := foo asInteger
> > foo2 first printStringRadix: 2
> >
> > any ideas on how to do this whether with printStringRadix: or
> otherwise?
> > The output should look something like :
> >
> > '0110010101100110' etc..
> >
> > Thx!
> >
> > -- Rick
> > _______________________________________________
> > vwnc mailing list
> > [hidden email]
> > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
> >
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Boris Popov, DeepCove Labs (SNN)
Sorry, yes, it's part of Seaside's Grease package these days,

SequenceableCollection class>>streamContents: aBlock
 | stream |
 stream := self new writeStream.
 aBlock value: stream.
 ^stream contents

-Boris

--
DeepCove Labs Ltd.
+1 (604) 689-0322
4th floor, 595 Howe Street
Vancouver, British Columbia
Canada V6C 2T5
http://tinyurl.com/r7uw4

PacNet Services (Europe) Ltd.
+353 (0)61 714-360
Shannon Airport House, SFZ
County Clare, Ireland
http://tinyurl.com/y952amr

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message header.
Unless otherwise indicated, it contains information that is private and
confidential. If you have received it in error, please notify the sender
and delete the entire message including any attachments.

Thank you.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On
Behalf Of Steven Kelly
Sent: 26 August 2010 10:50
To: [hidden email]
Subject: Re: [vwnc] Base conversion question..

#streamContents: isn't in my image - something from Seaside or Squeak?
Presumably something like this:

SequenceableCollection class>>streamContents: unaryBlock
        | ws |
        ws := WriteStream on: (self new: 100).
        unaryBlock value: ws.
        ^ws contents

Steve

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Boris Popov, DeepCove Labs (SNN)
> Sent: 26. elokuuta 2010 12:37
> To: [hidden email]
> Subject: Re: [vwnc] Base conversion question..
>
> Good point about padding,
>
> String streamContents:
> [:ws |
> 'abc' do:
> [:char |
> char asInteger
> printOn: ws
> paddedWith: $0
> to: 8
> base: 2]]
>
> -Boris
>
> --
> DeepCove Labs Ltd.
> +1 (604) 689-0322
> 4th floor, 595 Howe Street
> Vancouver, British Columbia
> Canada V6C 2T5
> http://tinyurl.com/r7uw4
>
> PacNet Services (Europe) Ltd.
> +353 (0)61 714-360
> Shannon Airport House, SFZ
> County Clare, Ireland
> http://tinyurl.com/y952amr
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message
header.
> Unless otherwise indicated, it contains information that is private
and

> confidential. If you have received it in error, please notify the
> sender and delete the entire message including any attachments.
>
> Thank you.
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Andres Valloud
> Sent: 26 August 2010 08:18
> To: [hidden email]
> Subject: Re: [vwnc] Base conversion question..
>
> Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
> like this (sort of)?
>
> answer := String new writeStream.
> foo := 'ABCDEFGHIJ' asByteArray.
> foo do:
> [:eachByte |
> eachByte
> printOn: answer
> paddedWith: $0
> to: 8
> base: 2
> ].
> answer contents
>
> Andres.
>
> On 8/26/2010 12:08 AM, Rick Flower wrote:
> > Hi all..
> >
> > I'm toying around with a new toy and need to convert an arbitrary
> > character string to a binary string as shown below to pump into an
> old
>
> > algorithm that assumes all input is in a binary string (long story
--
> > if it works I'll update the code).. I'm not completely sure how to
do

> > it.. I was toying around in the workspace but didn't get any output
> > with the following code:
> >
> > foo := 'ABCDEFGHIJ'.
> > foo2 := foo asInteger
> > foo2 first printStringRadix: 2
> >
> > any ideas on how to do this whether with printStringRadix: or
> otherwise?
> > The output should look something like :
> >
> > '0110010101100110' etc..
> >
> > Thx!
> >
> > -- Rick
> > _______________________________________________
> > vwnc mailing list
> > [hidden email]
> > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
> >
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Rick Flower
Thanks all for the various code snippets!  

I'll check them out!

-- Rick

On Thu, 26 Aug 2010 02:56:11 -0700, "Boris Popov, DeepCove Labs \(SNN\)"
<[hidden email]> wrote:

> Sorry, yes, it's part of Seaside's Grease package these days,
>
> SequenceableCollection class>>streamContents: aBlock
>  | stream |
>  stream := self new writeStream.
>  aBlock value: stream.
>  ^stream contents
>
> -Boris
>
> --
> DeepCove Labs Ltd.
> +1 (604) 689-0322
> 4th floor, 595 Howe Street
> Vancouver, British Columbia
> Canada V6C 2T5
> http://tinyurl.com/r7uw4
>
> PacNet Services (Europe) Ltd.
> +353 (0)61 714-360
> Shannon Airport House, SFZ
> County Clare, Ireland
> http://tinyurl.com/y952amr
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message header.
> Unless otherwise indicated, it contains information that is private and
> confidential. If you have received it in error, please notify the sender
> and delete the entire message including any attachments.
>
> Thank you.
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Steven Kelly
> Sent: 26 August 2010 10:50
> To: [hidden email]
> Subject: Re: [vwnc] Base conversion question..
>
> #streamContents: isn't in my image - something from Seaside or Squeak?
> Presumably something like this:
>
> SequenceableCollection class>>streamContents: unaryBlock
> | ws |
> ws := WriteStream on: (self new: 100).
> unaryBlock value: ws.
> ^ws contents
>
> Steve
>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On
>> Behalf Of Boris Popov, DeepCove Labs (SNN)
>> Sent: 26. elokuuta 2010 12:37
>> To: [hidden email]
>> Subject: Re: [vwnc] Base conversion question..
>>
>> Good point about padding,
>>
>> String streamContents:
>> [:ws |
>> 'abc' do:
>> [:char |
>> char asInteger
>> printOn: ws
>> paddedWith: $0
>> to: 8
>> base: 2]]
>>
>> -Boris
>>
>> --
>> DeepCove Labs Ltd.
>> +1 (604) 689-0322
>> 4th floor, 595 Howe Street
>> Vancouver, British Columbia
>> Canada V6C 2T5
>> http://tinyurl.com/r7uw4
>>
>> PacNet Services (Europe) Ltd.
>> +353 (0)61 714-360
>> Shannon Airport House, SFZ
>> County Clare, Ireland
>> http://tinyurl.com/y952amr
>>
>> CONFIDENTIALITY NOTICE
>>
>> This email is intended only for the persons named in the message
> header.
>> Unless otherwise indicated, it contains information that is private
> and
>> confidential. If you have received it in error, please notify the
>> sender and delete the entire message including any attachments.
>>
>> Thank you.
>>
>>
>> -----Original Message-----
>> From: [hidden email] [mailto:[hidden email]] On
>> Behalf Of Andres Valloud
>> Sent: 26 August 2010 08:18
>> To: [hidden email]
>> Subject: Re: [vwnc] Base conversion question..
>>
>> Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
>> like this (sort of)?
>>
>> answer := String new writeStream.
>> foo := 'ABCDEFGHIJ' asByteArray.
>> foo do:
>> [:eachByte |
>> eachByte
>> printOn: answer
>> paddedWith: $0
>> to: 8
>> base: 2
>> ].
>> answer contents
>>
>> Andres.
>>
>> On 8/26/2010 12:08 AM, Rick Flower wrote:
>> > Hi all..
>> >
>> > I'm toying around with a new toy and need to convert an arbitrary
>> > character string to a binary string as shown below to pump into an
>> old
>>
>> > algorithm that assumes all input is in a binary string (long story
> --
>> > if it works I'll update the code).. I'm not completely sure how to
> do
>> > it.. I was toying around in the workspace but didn't get any output
>> > with the following code:
>> >
>> > foo := 'ABCDEFGHIJ'.
>> > foo2 := foo asInteger
>> > foo2 first printStringRadix: 2
>> >
>> > any ideas on how to do this whether with printStringRadix: or
>> otherwise?
>> > The output should look something like :
>> >
>> > '0110010101100110' etc..
>> >
>> > Thx!
>> >
>> > -- Rick
>> > _______________________________________________
>> > vwnc mailing list
>> > [hidden email]
>> > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>> >
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Alan Knight-2
All of these seem to be ignoring the issue of encodings. Which will be fine if your character string is ASCII. But if not, you really ought to be specifying an encoding on asByteArray:.

At 10:14 AM 2010-08-26, Rick Flower wrote:
Thanks all for the various code snippets! 

I'll check them out!

-- Rick

On Thu, 26 Aug 2010 02:56:11 -0700, "Boris Popov, DeepCove Labs \(SNN\)"
<[hidden email]> wrote:
> Sorry, yes, it's part of Seaside's Grease package these days,
>
> SequenceableCollection class>>streamContents: aBlock
>  | stream |
>  stream := self new writeStream.
>  aBlock value: stream.
>  ^stream contents
>
> -Boris
>
> --
> DeepCove Labs Ltd.
> +1 (604) 689-0322
> 4th floor, 595 Howe Street
> Vancouver, British Columbia
> Canada V6C 2T5
> http://tinyurl.com/r7uw4
>
> PacNet Services (Europe) Ltd.
> +353 (0)61 714-360
> Shannon Airport House, SFZ
> County Clare, Ireland
> http://tinyurl.com/y952amr
>
> CONFIDENTIALITY NOTICE
>
> This email is intended only for the persons named in the message header.
> Unless otherwise indicated, it contains information that is private and
> confidential. If you have received it in error, please notify the sender
> and delete the entire message including any attachments.
>
> Thank you.
>
>
> -----Original Message-----
> From: [hidden email] [[hidden email]] On
> Behalf Of Steven Kelly
> Sent: 26 August 2010 10:50
> To: [hidden email]
> Subject: Re: [vwnc] Base conversion question..
>
> #streamContents: isn't in my image - something from Seaside or Squeak?
> Presumably something like this:
>
> SequenceableCollection class>>streamContents: unaryBlock
>       | ws |
>       ws := WriteStream on: (self new: 100).
>       unaryBlock value: ws.
>       ^ws contents
>
> Steve
>
>> -----Original Message-----
>> From: [hidden email] [[hidden email]] On
>> Behalf Of Boris Popov, DeepCove Labs (SNN)
>> Sent: 26. elokuuta 2010 12:37
>> To: [hidden email]
>> Subject: Re: [vwnc] Base conversion question..
>>
>> Good point about padding,
>>
>> String streamContents:
>>               [:ws |
>>               'abc' do:
>>                                 [:char |
>>                                 char asInteger
>>                                          printOn: ws
>>                                          paddedWith: $0
>>                                          to: 8
>>                                          base: 2]]
>>
>> -Boris
>>
>> --
>> DeepCove Labs Ltd.
>> +1 (604) 689-0322
>> 4th floor, 595 Howe Street
>> Vancouver, British Columbia
>> Canada V6C 2T5
>> http://tinyurl.com/r7uw4
>>
>> PacNet Services (Europe) Ltd.
>> +353 (0)61 714-360
>> Shannon Airport House, SFZ
>> County Clare, Ireland
>> http://tinyurl.com/y952amr
>>
>> CONFIDENTIALITY NOTICE
>>
>> This email is intended only for the persons named in the message
> header.
>> Unless otherwise indicated, it contains information that is private
> and
>> confidential. If you have received it in error, please notify the
>> sender and delete the entire message including any attachments.
>>
>> Thank you.
>>
>>
>> -----Original Message-----
>> From: [hidden email] [[hidden email]] On
>> Behalf Of Andres Valloud
>> Sent: 26 August 2010 08:18
>> To: [hidden email]
>> Subject: Re: [vwnc] Base conversion question..
>>
>> Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
>> like this (sort of)?
>>
>> answer := String new writeStream.
>> foo := 'ABCDEFGHIJ' asByteArray.
>> foo do:
>>      [:eachByte |
>>               eachByte
>>                        printOn: answer
>>                        paddedWith: $0
>>                        to: 8
>>                        base: 2
>>      ].
>> answer contents
>>
>> Andres.
>>
>> On 8/26/2010 12:08 AM, Rick Flower wrote:
>> > Hi all..
>> >
>> > I'm toying around with a new toy and need to convert an arbitrary
>> > character string to a binary string as shown below to pump into an
>> old
>>
>> > algorithm that assumes all input is in a binary string (long story
> --
>> > if it works I'll update the code).. I'm not completely sure how to
> do
>> > it.. I was toying around in the workspace but didn't get any output
>> > with the following code:
>> >
>> > foo := 'ABCDEFGHIJ'.
>> > foo2 := foo asInteger
>> > foo2 first printStringRadix: 2
>> >
>> > any ideas on how to do this whether with printStringRadix: or
>> otherwise?
>> > The output should look something like :
>> >
>> > '0110010101100110' etc..
>> >
>> > Thx!
>> >
>> > -- Rick
>> > _______________________________________________
>> > vwnc mailing list
>> > [hidden email]
>> > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>> >
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>
>> _______________________________________________
>> vwnc mailing list
>> [hidden email]
>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

--
Alan Knight [|], Engineering Manager, Cincom Smalltalk

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Base conversion question..

Rick Flower
Thanks Alan!  In this case it is ASCII but I will keep that
in mind regardless.

On Thu, 26 Aug 2010 10:20:43 -0400, Alan Knight <[hidden email]> wrote:
> All of these seem to be ignoring the issue of encodings. Which will be
> fine if your character string is ASCII. But if not, you really ought to
be

> specifying an encoding on asByteArray:.
>
> At 10:14 AM 2010-08-26, Rick Flower wrote:
>>Thanks all for the various code snippets!  
>>
>>I'll check them out!
>>
>>-- Rick
>>
>>On Thu, 26 Aug 2010 02:56:11 -0700, "Boris Popov, DeepCove Labs \(SNN\)"
>><[hidden email]> wrote:
>>> Sorry, yes, it's part of Seaside's Grease package these days,
>>>
>>> SequenceableCollection class>>streamContents: aBlock
>>>  | stream |
>>>  stream := self new writeStream.
>>>  aBlock value: stream.
>>>  ^stream contents
>>>
>>> -Boris
>>>
>>> --
>>> DeepCove Labs Ltd.
>>> +1 (604) 689-0322
>>> 4th floor, 595 Howe Street
>>> Vancouver, British Columbia
>>> Canada V6C 2T5
>>> http://tinyurl.com/r7uw4
>>>
>>> PacNet Services (Europe) Ltd.
>>> +353 (0)61 714-360
>>> Shannon Airport House, SFZ
>>> County Clare, Ireland
>>> http://tinyurl.com/y952amr
>>>
>>> CONFIDENTIALITY NOTICE
>>>
>>> This email is intended only for the persons named in the message
header.
>>> Unless otherwise indicated, it contains information that is private
and
>>> confidential. If you have received it in error, please notify the
sender

>>> and delete the entire message including any attachments.
>>>
>>> Thank you.
>>>
>>>
>>> -----Original Message-----
>>> From: [hidden email] [mailto:[hidden email]] On
>>> Behalf Of Steven Kelly
>>> Sent: 26 August 2010 10:50
>>> To: [hidden email]
>>> Subject: Re: [vwnc] Base conversion question..
>>>
>>> #streamContents: isn't in my image - something from Seaside or Squeak?
>>> Presumably something like this:
>>>
>>> SequenceableCollection class>>streamContents: unaryBlock
>>>       | ws |
>>>       ws := WriteStream on: (self new: 100).
>>>       unaryBlock value: ws.
>>>       ^ws contents
>>>
>>> Steve
>>>
>>>> -----Original Message-----
>>>> From: [hidden email] [mailto:[hidden email]] On
>>>> Behalf Of Boris Popov, DeepCove Labs (SNN)
>>>> Sent: 26. elokuuta 2010 12:37
>>>> To: [hidden email]
>>>> Subject: Re: [vwnc] Base conversion question..
>>>>
>>>> Good point about padding,
>>>>
>>>> String streamContents:
>>>>              [:ws |
>>>>              'abc' do:
>>>>                              [:char |
>>>>                              char asInteger
>>>>                                      printOn: ws
>>>>                                      paddedWith: $0
>>>>                                      to: 8
>>>>                                      base: 2]]
>>>>
>>>> -Boris
>>>>
>>>> --
>>>> DeepCove Labs Ltd.
>>>> +1 (604) 689-0322
>>>> 4th floor, 595 Howe Street
>>>> Vancouver, British Columbia
>>>> Canada V6C 2T5
>>>> http://tinyurl.com/r7uw4
>>>>
>>>> PacNet Services (Europe) Ltd.
>>>> +353 (0)61 714-360
>>>> Shannon Airport House, SFZ
>>>> County Clare, Ireland
>>>> http://tinyurl.com/y952amr
>>>>
>>>> CONFIDENTIALITY NOTICE
>>>>
>>>> This email is intended only for the persons named in the message
>>> header.
>>>> Unless otherwise indicated, it contains information that is private
>>> and
>>>> confidential. If you have received it in error, please notify the
>>>> sender and delete the entire message including any attachments.
>>>>
>>>> Thank you.
>>>>
>>>>
>>>> -----Original Message-----
>>>> From: [hidden email] [mailto:[hidden email]] On
>>>> Behalf Of Andres Valloud
>>>> Sent: 26 August 2010 08:18
>>>> To: [hidden email]
>>>> Subject: Re: [vwnc] Base conversion question..
>>>>
>>>> Maybe you can reuse something like 'ABCDEFGHIJ' asByteArray, perhaps
>>>> like this (sort of)?
>>>>
>>>> answer := String new writeStream.
>>>> foo := 'ABCDEFGHIJ' asByteArray.
>>>> foo do:
>>>>      [:eachByte |
>>>>              eachByte
>>>>                      printOn: answer
>>>>                      paddedWith: $0
>>>>                      to: 8
>>>>                      base: 2
>>>>      ].
>>>> answer contents
>>>>
>>>> Andres.
>>>>
>>>> On 8/26/2010 12:08 AM, Rick Flower wrote:
>>>> > Hi all..
>>>> >
>>>> > I'm toying around with a new toy and need to convert an arbitrary
>>>> > character string to a binary string as shown below to pump into an
>>>> old
>>>>
>>>> > algorithm that assumes all input is in a binary string (long story
>>> --
>>>> > if it works I'll update the code).. I'm not completely sure how to
>>> do
>>>> > it.. I was toying around in the workspace but didn't get any output

>>>> > with the following code:
>>>> >
>>>> > foo := 'ABCDEFGHIJ'.
>>>> > foo2 := foo asInteger
>>>> > foo2 first printStringRadix: 2
>>>> >
>>>> > any ideas on how to do this whether with printStringRadix: or
>>>> otherwise?
>>>> > The output should look something like :
>>>> >
>>>> > '0110010101100110' etc..
>>>> >
>>>> > Thx!
>>>> >
>>>> > -- Rick
>>>> > _______________________________________________
>>>> > vwnc mailing list
>>>> > [hidden email]
>>>> > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>>> >
>>>> _______________________________________________
>>>> vwnc mailing list
>>>> [hidden email]
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>>>
>>>> _______________________________________________
>>>> vwnc mailing list
>>>> [hidden email]
>>>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>>
>>> _______________________________________________
>>> vwnc mailing list
>>> [hidden email]
>>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>>
>>> _______________________________________________
>>> vwnc mailing list
>>> [hidden email]
>>> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>>_______________________________________________
>>vwnc mailing list
>>[hidden email]
>>http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
> --
> Alan Knight [|], Engineering Manager, Cincom Smalltalk
> [hidden email]
> [hidden email]
> http://www.cincom.com/smalltalk
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc