1
1
/*
2
2
* *****************************************************************************
3
- * Copyright (C) 2014-2024 Dennis Sheirer
3
+ * Copyright (C) 2014-2025 Dennis Sheirer
4
4
*
5
5
* This program is free software: you can redistribute it and/or modify
6
6
* it under the terms of the GNU General Public License as published by
@@ -415,8 +415,8 @@ public boolean[] getBits(int startIndex, int endIndex)
415
415
boolean [] returnValue = null ;
416
416
417
417
if (startIndex >= 0 &&
418
- startIndex < endIndex &&
419
- endIndex < mSize )
418
+ startIndex < endIndex &&
419
+ endIndex < mSize )
420
420
{
421
421
returnValue = new boolean [endIndex - startIndex + 1 ];
422
422
@@ -447,7 +447,7 @@ public int getInt(int[] bits)
447
447
if (bits .length > 32 )
448
448
{
449
449
throw new IllegalArgumentException ("Overflow - must be 32 bits "
450
- + "or less to fit into a primitive integer value" );
450
+ + "or less to fit into a primitive integer value" );
451
451
}
452
452
453
453
int value = 0 ;
@@ -676,7 +676,7 @@ public int getInt(int[] bits, int offset)
676
676
if (bits .length > 32 )
677
677
{
678
678
throw new IllegalArgumentException ("Overflow - must be 32 bits "
679
- + "or less to fit into a primitive integer value" );
679
+ + "or less to fit into a primitive integer value" );
680
680
}
681
681
682
682
int value = 0 ;
@@ -711,6 +711,28 @@ public void setInt(int value, int[] indices)
711
711
}
712
712
}
713
713
714
+ /**
715
+ * Sets the integer value to the field described by the argument.
716
+ * @param value to set
717
+ * @param intField describing the indices of the field.
718
+ */
719
+ public void setInt (int value , IntField intField )
720
+ {
721
+ for (int x = 0 ; x < intField .width (); x ++)
722
+ {
723
+ int mask = 1 << (intField .width () - x - 1 );
724
+
725
+ if ((value & mask ) == mask )
726
+ {
727
+ set (intField .start () + x );
728
+ }
729
+ else
730
+ {
731
+ clear (intField .start () + x );
732
+ }
733
+ }
734
+ }
735
+
714
736
/**
715
737
* Returns the byte value represented by the bit array
716
738
*
@@ -724,7 +746,7 @@ public byte getByte(int[] bits)
724
746
if (bits .length != 8 )
725
747
{
726
748
throw new IllegalArgumentException ("Invalid - there must be 8"
727
- + "indexes to form a proper byte" );
749
+ + "indexes to form a proper byte" );
728
750
}
729
751
730
752
int value = 0 ;
@@ -756,7 +778,7 @@ public byte getByte(int[] bits, int offset)
756
778
if (bits .length != 8 )
757
779
{
758
780
throw new IllegalArgumentException ("Invalid - there must be 8"
759
- + "indexes to form a proper byte" );
781
+ + "indexes to form a proper byte" );
760
782
}
761
783
762
784
int value = 0 ;
@@ -884,7 +906,7 @@ public long getLong(int[] bits)
884
906
if (bits .length > 64 )
885
907
{
886
908
throw new IllegalArgumentException ("Overflow - must be 64 bits "
887
- + "or less to fit into a primitive long value" );
909
+ + "or less to fit into a primitive long value" );
888
910
}
889
911
890
912
long value = 0 ;
@@ -916,7 +938,7 @@ public long getLong(int[] bits, int offset)
916
938
if (bits .length > 64 )
917
939
{
918
940
throw new IllegalArgumentException ("Overflow - must be 64 bits "
919
- + "or less to fit into a primitive long value" );
941
+ + "or less to fit into a primitive long value" );
920
942
}
921
943
922
944
long value = 0 ;
@@ -1004,7 +1026,7 @@ else if(bits.length <= 64)
1004
1026
else
1005
1027
{
1006
1028
throw new IllegalArgumentException ("BitSetBuffer.getHex() "
1007
- + "maximum array length is 63 bits" );
1029
+ + "maximum array length is 63 bits" );
1008
1030
}
1009
1031
}
1010
1032
@@ -1025,7 +1047,7 @@ public int getInt(int start, int end)
1025
1047
if (FastMath .abs (end - start ) > 32 )
1026
1048
{
1027
1049
throw new IllegalArgumentException ("Overflow - must be 32 bits "
1028
- + "or less to fit into a primitive integer value" );
1050
+ + "or less to fit into a primitive integer value" );
1029
1051
}
1030
1052
1031
1053
int value = 0 ;
@@ -1100,7 +1122,7 @@ public long getLong(int start, int end)
1100
1122
if (FastMath .abs (end - start ) > 64 )
1101
1123
{
1102
1124
throw new IllegalArgumentException ("Overflow - must be 64 bits "
1103
- + "or less to fit into a primitive long value" );
1125
+ + "or less to fit into a primitive long value" );
1104
1126
}
1105
1127
1106
1128
long value = 0 ;
@@ -1255,7 +1277,7 @@ public static BinaryMessage load(String message)
1255
1277
if (!message .matches ("[01]*" ))
1256
1278
{
1257
1279
throw new IllegalArgumentException (
1258
- "Message must contain only zeros and ones" );
1280
+ "Message must contain only zeros and ones" );
1259
1281
}
1260
1282
1261
1283
BinaryMessage buffer = new BinaryMessage (message .length ());
0 commit comments