5353 * <strong>Example:</strong>
5454 * <pre>
5555 * Bytes b = Bytes.from(array);
56- * b.negate ();
56+ * b.not ();
5757 * System.out.println(b.encodeHex());
5858 * </pre>
5959 */
@@ -265,7 +265,7 @@ public static Bytes from(ByteBuffer buffer) {
265265 }
266266
267267 /**
268- * Creates a new instance from given BitSet.
268+ * Creates a new instance from given {@link BitSet} .
269269 *
270270 * @param set to get the byte array from
271271 * @return new instance
@@ -274,6 +274,17 @@ public static Bytes from(BitSet set) {
274274 return wrap (set .toByteArray ());
275275 }
276276
277+ /**
278+ * /**
279+ * Creates a new instance from given {@link BigInteger}.
280+ *
281+ * @param bigInteger to get the byte array from
282+ * @return new instance
283+ */
284+ public static Bytes from (BigInteger bigInteger ) {
285+ return wrap (bigInteger .toByteArray ());
286+ }
287+
277288 /**
278289 * Reads given input stream and creates a new instance from read data
279290 *
@@ -574,13 +585,13 @@ public Bytes or(byte[] secondArray) {
574585 }
575586
576587 /**
577- * Bitwise negate operation on the whole internal byte array.
588+ * Bitwise not operation on the whole internal byte array.
578589 * See the considerations about possible in-place operation in {@link #transform(BytesTransformer)}.
579590 *
580591 * @return negated instance
581592 * @see <a href="https://en.wikipedia.org/wiki/Bitwise_operation#NOT">Bitwise operators: NOT</a>
582593 */
583- public Bytes negate () {
594+ public Bytes not () {
584595 return transform (new BytesTransformer .NegateTransformer ());
585596 }
586597
@@ -610,6 +621,27 @@ public Bytes rightShift(int shiftCount) {
610621 return transform (new BytesTransformer .ShiftTransformer (shiftCount , BytesTransformer .ShiftTransformer .Type .RIGHT_SHIFT ));
611622 }
612623
624+ /**
625+ * Returns a Byte whose value is equivalent to this Byte with the designated bit set to newBitValue. Bits start to count from the LSB (ie. Bytes.from(0).switchBit(0,true) == 1)
626+ *
627+ * @param bitPosition not to confuse with byte position
628+ * @param newBitValue if true set to 1, 0 otherwise
629+ * @return instance with bit switched
630+ */
631+ public Bytes switchBit (int bitPosition , boolean newBitValue ) {
632+ return transform (new BytesTransformer .BitSwitchTransformer (bitPosition , newBitValue ));
633+ }
634+
635+ /**
636+ * Returns a Byte whose value is equivalent to this Byte with the designated bit switched.
637+ *
638+ * @param bitPosition not to confuse with byte position
639+ * @return instance with bit switched
640+ */
641+ public Bytes switchBit (int bitPosition ) {
642+ return transform (new BytesTransformer .BitSwitchTransformer (bitPosition , null ));
643+ }
644+
613645 /**
614646 * Creates a new instance with a copy of the internal byte array and all other attributes.
615647 *
@@ -704,27 +736,6 @@ public Bytes resize(int newByteLength) {
704736 return transform (new BytesTransformer .ResizeTransformer (newByteLength ));
705737 }
706738
707- /**
708- * Returns a Byte whose value is equivalent to this Byte with the designated bit set to newBitValue. Bits start to count from the LSB (ie. Bytes.from(0).switchBit(0,true) == 1)
709- *
710- * @param bitPosition not to confuse with byte position
711- * @param newBitValue if true set to 1, 0 otherwise
712- * @return instance with bit switched
713- */
714- public Bytes switchBit (int bitPosition , boolean newBitValue ) {
715- return transform (new BytesTransformer .BitSwitchTransformer (bitPosition , newBitValue ));
716- }
717-
718- /**
719- * Returns a Byte whose value is equivalent to this Byte with the designated bit switched.
720- *
721- * @param bitPosition not to confuse with byte position
722- * @return instance with bit switched
723- */
724- public Bytes switchBit (int bitPosition ) {
725- return transform (new BytesTransformer .BitSwitchTransformer (bitPosition , null ));
726- }
727-
728739 /**
729740 * Generic transformation of this instance.
730741 * <p>
@@ -973,23 +984,7 @@ private ByteBuffer internalBuffer() {
973984 return ByteBuffer .wrap (internalArray ()).order (byteOrder );
974985 }
975986
976- /**
977- * The internal byte array wrapped in a {@link BigInteger} instance.
978- * <p>
979- * If the internal byte order is {@link ByteOrder#LITTLE_ENDIAN}, a copy of the internal
980- * array will be reversed and used as backing array with the big integer. Otherwise the internal
981- * array will be used directly.
982- *
983- * @return big integer
984- * @throws ReadOnlyBufferException if this is a read-only instance
985- */
986- public BigInteger bigInteger () {
987- if (byteOrder == ByteOrder .LITTLE_ENDIAN ) {
988- return new BigInteger (new BytesTransformer .ReverseTransformer ().transform (array (), false ));
989- } else {
990- return new BigInteger (array ());
991- }
992- }
987+
993988
994989 /**
995990 * Returns a mutable version of this instance with sharing the same underlying byte-array.
@@ -1182,6 +1177,23 @@ public BitSet toBitSet() {
11821177 return BitSet .valueOf (internalArray ());
11831178 }
11841179
1180+ /**
1181+ * The internal byte array wrapped in a {@link BigInteger} instance.
1182+ * <p>
1183+ * If the internal byte order is {@link ByteOrder#LITTLE_ENDIAN}, a copy of the internal
1184+ * array will be reversed and used as backing array with the big integer. Otherwise the internal
1185+ * array will be used directly.
1186+ *
1187+ * @return big integer
1188+ */
1189+ public BigInteger toBigInteger () {
1190+ if (byteOrder == ByteOrder .LITTLE_ENDIAN ) {
1191+ return new BigInteger (new BytesTransformer .ReverseTransformer ().transform (internalArray (), false ));
1192+ } else {
1193+ return new BigInteger (internalArray ());
1194+ }
1195+ }
1196+
11851197 /**
11861198 * If the underlying byte array is smaller than or equal to 1 byte / 8 bit returns unsigned two-complement
11871199 * representation for a Java byte value.
0 commit comments