File tree Expand file tree Collapse file tree
main/java/com/conversions
test/java/com/conversions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33public class BinaryToGray
44{
55 /* This method convert the binary number into gray code
6- @param binaryno need to convert binary number into gray code
6+ @param binarycode need to convert binary number into gray code
77 @return graycode return as string
88 */
99
1010 public String binaryToGray (String binarycode )
1111 {
1212
13- String graycode =Character .toString (binarycode .charAt (0 ));
14-
13+ String graycode = Character .toString (binarycode .charAt (0 ));
1514
16- for (int i = 0 ; i < binarycode .length ()- 1 ; i ++)
15+ for (int i = 0 ; i < binarycode .length () - 1 ; i ++)
1716 {
1817
19- if (binarycode .charAt (i )== binarycode .charAt (i +1 ))
20- graycode = graycode + "0" ;
18+ if (binarycode .charAt (i ) == binarycode .charAt (i +1 ))
19+ graycode = graycode + "0" ;
2120 else
22- graycode = graycode + "1" ;
21+ graycode = graycode + "1" ;
2322
2423 }
2524
2625 return graycode ;
27-
2826 }
2927
3028}
Original file line number Diff line number Diff line change 77public class BinaryToGrayTest
88{
99
10-
1110 @ Test
1211 public void testBinaryToGray ()
1312 {
14- BinaryToGray btog = new BinaryToGray ();
15- assertEquals ("1101" ,btog .binaryToGray ("1001" ));
13+ BinaryToGray btog = new BinaryToGray ();
14+ assertEquals ("1101" , btog .binaryToGray ("1001" ));
1615 assertEquals ("11010011101" ,btog .binaryToGray ("10011101001" ));
1716 }
1817
You can’t perform that action at this time.
0 commit comments