[Pharo-project] Issue 3968 in pharo: ByteArray>>#asInteger
Status: New Owner: ---- New issue 3968 by sven.van...@gmail.com: 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
Updates: Status: FixProposed Labels: Milestone-1.3 Comment #1 on issue 3968 by marcus.d...@gmail.com: ByteArray>>#asInteger http://code.google.com/p/pharo/issues/detail?id=3968 (No comment was entered for this change.)
participants (1)
-
pharoï¼ googlecode.com