You could add your own #uint32LittleEndian on PositionableStream:

PositionableStream>>uint32LittleEndian

      ^ self next
            + (self next bitShift: 8)
                  + (self next bitShift: 16)
                        + (self next bitShift: 24)

#[1 2 3 4] readStream uint32LittleEndian hex. '16r4030201' 

Another possibility would be to convert the bytes into a WordArray:

#[1 2 3 4] readStream uint32 hex. --> '16r1020304' 
((#[1 2 3 4] readStream next: 4) changeClassTo: WordArray) first hex. --> '16r4030201' 

For reading many numbers from the stream, this should be even more efficient than #uint32 as no manual combination of bytes happens in the image:

(((1 to: 16) asByteArray readStream next: 16) changeClassTo: WordArray) collect: #hex as: Array. --> #('16r4030201' '16r8070605' '16rC0B0A09' '16r100F0E0D') 

Best,
Christoph

Von: Yoshiki Ohshima via Beginners <beginners@lists.squeakfoundation.org>
Gesendet: Mittwoch, 8. Mai 2024 01:37 Uhr
An: A friendly place to get answers to even the most basic questions about Squeak. <beginners@lists.squeakfoundation.org>
Cc: Yoshiki Ohshima <Yoshiki.Ohshima@acm.org>
Betreff: [Newbies] Re: Need ByteArray Interpreted as Base 10 UnsignedInt of 32 bits.
 
When you say "result is simply incorrect", can you explain the way it is incorrect? Is it perhaps the byte order issue? (I am not familiar with "doom wads" so there may be an obvious answer).

I would start from code snippet that looks like:

(ReadStream on: #(1 2 3 4)) uint32 hex

That evaluates to '16r1020304'.

And replace the (ReadStream ...) part with your data.

On Tue, May 7, 2024 at 6:55 AM Cody Sevier <sevierit@gmail.com> wrote:
I should note that I have tried to use the positionableStreams uint32 message for of advancing the stream but the result is simply incorrect.

Cody

On Tue, May 7, 2024 at 8:43 AM Cody Sevier <sevierit@gmail.com> wrote:
Hello Squeakers,

I have an algorithm for reading doom wads working in Pharo that I would like to convert to Squeak, however, I cant for the life of me figure out how to interpret a byte array of 4 bytes as an Unsigned Int. I see that a ByteArray IS an UnsignedIntCollection, but cant seem to figure out how to use it as such. 

Functional Pharo:
binaryStream := wad binaryReadStream.
wadType := (binaryStream next: 4) asString.
numberOfDirectories := (binaryStream next: 4) uint32AtOffset: 0.
byteOffsetToDirectories := (binaryStream next: 4) uint32AtOffset: 0.

Semi Functional Squeak:
binaryStream := (FileStream readOnlyFileNamed: aFileLocation) binary yourself .
wadType := (binaryStream next: 4) asString.
numberOfDirectories :=(binaryStream next: 4). ?
byteOffsetToDirectories := (binaryStream next: 4). ?

Thanks for your assistance!

Kind Regards,
Cody
_______________________________________________
Beginners mailing list -- beginners@lists.squeakfoundation.org
To unsubscribe send an email to beginners-leave@lists.squeakfoundation.org


--
-- Yoshiki