commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] [Commented] (LANG-801) Util for conversion between primitive types
Date Thu, 27 Sep 2012 21:03:07 GMT


Sebb commented on LANG-801:

There aeems to be a lot of unnecessary conversion to/from Integer/Short etc. instead of sticking
to primitive types.

For example:

    Short bits = (short)(0xff & (src >> shift));
    dst[dstPos + i] = bits.byteValue();

could be expressed as

    dst[dstPos + i] = (byte) (0xff & (src >> shift));

> Util for conversion between primitive types
> -------------------------------------------
>                 Key: LANG-801
>                 URL:
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Sebastien Riou
>            Assignee: Joerg Schaible
>            Priority: Minor
>         Attachments: patch_Conversion.txt
> A utility class to convert data from one primitive type to another, in the most commonly
used fashions (big endian/little endian byte order, lsb first or msb first).
> It also deals with arrays of primitive types and String containing hexadecimal numbers.
> Such conversions are needed when dealing with embedded software or hardware modeling/design.
> I attach a initial version which deals with the "default" encoding, the one which seems
the most natural on the JVM: little endian byte ordering, and, within a byte, lsb first.
> I plan to implement the other encoding I need:
>  - big endian, lsb first
>  - big endian, msb first 
> So far I implemented about half of the methods needed to cover the default encoding:
>  - methods to convert a large data type into an array of a smaller data type (longToBytes
for example)
>  - methods to convert an array of a small data type into a larger data type (bytesToLong
for example)
> The remaining half consist of the methods to convert from an array of a data type into
an array of another data type (bytesToLongs, LongsToBytes)
> Once this is available for different encodings, the most useful part can be done: the
"bridge" methods to convert from one encoding to another

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message