Status: New
Owner: ----

New issue 3968 by [email protected]: 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 via email to