File tree 2 files changed +17
-3
lines changed
main/java/com/thealgorithms/conversions
test/java/com/thealgorithms/conversions
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ public class HexaDecimalToBinary {
5
5
6
6
private final int LONG_BITS = 8 ;
7
7
8
- public void convert (String numHex ) {
8
+ public String convert (String numHex ) {
9
9
// String a HexaDecimal:
10
10
int conHex = Integer .parseInt (numHex , 16 );
11
11
// Hex a Binary:
12
12
String binary = Integer .toBinaryString (conHex );
13
13
// Output:
14
- System . out . println ( numHex + " = " + completeDigits (binary ) );
14
+ return completeDigits (binary );
15
15
}
16
16
17
17
public String completeDigits (String binNum ) {
@@ -39,7 +39,7 @@ public static void main(String[] args) {
39
39
HexaDecimalToBinary objConvert = new HexaDecimalToBinary ();
40
40
41
41
for (String num : hexNums ) {
42
- objConvert .convert (num );
42
+ System . out . println ( num + " = " + objConvert .convert (num ) );
43
43
}
44
44
}
45
45
}
Original file line number Diff line number Diff line change
1
+ package com .thealgorithms .conversions ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+ import static org .junit .jupiter .api .Assertions .*;
5
+
6
+ public class HexaDecimalToBinaryTest {
7
+
8
+ @ Test
9
+ public void testHexaDecimalToBinary (){
10
+ HexaDecimalToBinary hexaDecimalToBinary = new HexaDecimalToBinary ();
11
+ assertEquals ("1111111111111111111111111111111" , hexaDecimalToBinary .convert ("7fffffff" ));
12
+ assertEquals ("101010111100110111101111" , hexaDecimalToBinary .convert ("abcdef" ));
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments