Issue 3968 in pharo: ByteArray>>#asInteger

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

Issue 3968 in pharo: ByteArray>>#asInteger

pharo
Status: New
Owner: ----

New issue 3968 by [hidden email]: ByteArray>>#asInteger
http://code.google.com/p/pharo/issues/detail?id=3968

Pharo 1.2.1 (proposal for 1.3)

Since the methods #asByteArray and #asByteArrayOfSize: (part of  
System-Hashing-Core) exist, it would be logical that the inverse exists as  
well:

ByteArray>>#asInteger
        | integer |
        integer := 0.
        self withIndexDo: [ :each :index |
                integer := integer + (each bitShift: (bytes size - index) * 8) ].
        ^ integer

Granted, these methods pick the most common ordering (network byte order,  
most significant byte first, big endian). We should note that in the  
comments. Adding endianness as a parameter would unnecessarily complicate  
the interface. Maybe a littleEndian variant could be provided  
(#asIntegerLittleEndian, #asByteArrayLittleEndian,  
#asByteArrayLittleEndianOfSize:) ?

I've written this already in two projects, anybody else thinks this would  
be handy ?

Sven


Reply | Threaded
Open this post in threaded view
|

Re: Issue 3968 in pharo: ByteArray>>#asInteger

pharo
Updates:
        Status: FixProposed
        Labels: Milestone-1.3

Comment #1 on issue 3968 by [hidden email]: ByteArray>>#asInteger
http://code.google.com/p/pharo/issues/detail?id=3968

(No comment was entered for this change.)