@@ -93,7 +93,7 @@ public static byte[] asBytes (double value) {
9393 * @since 1.3.1
9494 */
9595 public static short asUnsignedByte (byte value ) {
96- return asUnsignedByte ( new byte [] { value } );
96+ return ( short ) ( value & 0xff );
9797 }
9898
9999 /**
@@ -111,15 +111,28 @@ public static short asUnsignedByte (@NonNull byte[] bytes) {
111111
112112 public static short asShort (@ NonNull byte [] bytes ) {
113113 val aligned = align (bytes , Short .BYTES );
114- return (short ) ((aligned [0 ] << 8 ) | (aligned [1 ] & 0xff ));
114+ return (short ) ((aligned [0 ] << 8 ) | (aligned [1 ] & 0xff ));
115+ }
116+
117+ /**
118+ * Transforms byte array to unsigned short integer value as integer.
119+ *
120+ * @param value signed short value
121+ *
122+ * @return unsigned short as integer
123+ *
124+ * @since 1.5.2
125+ */
126+ public static int asUnsignedShort (short value ) {
127+ return value & 0xFFFF ;
115128 }
116129
117130 /**
118131 * Transforms byte array to unsigned short integer value as integer.
119132 *
120133 * @param bytes byte array
121134 *
122- * @return unsigned short integer
135+ * @return unsigned short as integer
123136 *
124137 * @since 1.3.1
125138 */
@@ -129,23 +142,36 @@ public static int asUnsignedShort (@NonNull byte[] bytes) {
129142
130143 public static char asChar (@ NonNull byte [] bytes ) {
131144 val aligned = align (bytes , Short .BYTES );
132- return (char ) ((aligned [0 ] << 8 ) | (aligned [1 ] & 0xff ));
145+ return (char ) ((aligned [0 ] << 8 ) | (aligned [1 ] & 0xff ));
133146 }
134147
135148 public static int asInteger (@ NonNull byte [] bytes ) {
136149 val aligned = align (bytes , Integer .BYTES );
137150 return (aligned [0 ] << 24 )
138151 | ((aligned [1 ] & 0xff ) << 16 )
139- | ((aligned [2 ] & 0xff ) << 8 )
152+ | ((aligned [2 ] & 0xff ) << 8 )
140153 | (aligned [3 ] & 0xff );
141154 }
142155
156+ /**
157+ * Transforms byte array to unsigned integer value as long integer.
158+ *
159+ * @param value signed integer value
160+ *
161+ * @return unsigned integer as long
162+ *
163+ * @since 1.5.2
164+ */
165+ public static long asUnsignedInteger (int value ) {
166+ return value & 0x00000000FFFFFFFFL ;
167+ }
168+
143169 /**
144170 * Transforms byte array to unsigned integer value as long integer.
145171 *
146172 * @param bytes byte array
147173 *
148- * @return unsigned integer
174+ * @return unsigned integer as long
149175 *
150176 * @since 1.3.1
151177 */
@@ -161,7 +187,7 @@ public static long asLong (@NonNull byte[] bytes) {
161187 | (((long ) aligned [3 ] & 0xff ) << 32 )
162188 | (((long ) aligned [4 ] & 0xff ) << 24 )
163189 | (((long ) aligned [5 ] & 0xff ) << 16 )
164- | (((long ) aligned [6 ] & 0xff ) << 8 )
190+ | (((long ) aligned [6 ] & 0xff ) << 8 )
165191 | ((long ) aligned [7 ] & 0xff );
166192 }
167193
0 commit comments