[Pharo-project] Issue 3968 in pharo: ByteArray>>#asInteger

pharo at googlecode.com pharo at googlecode.com
Thu Apr 7 09:58:57 CEST 2011

Status: New
Owner: ----

New issue 3968 by sven.van... at gmail.com: ByteArray>>#asInteger

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  

	| 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 ?


More information about the Pharo-project mailing list