Skip to content

Commit 91c1992

Browse files
committed
Commit BinaryToGray
1 parent 39806e3 commit 91c1992

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package src.main.java.com.conversions;
2+
3+
public class BinaryToGray
4+
{
5+
/* This method convert the binary number into gray code
6+
@param binaryno need to convert binary number into gray code
7+
@return graycode return as string
8+
*/
9+
10+
public String binaryToGray(String binarycode)
11+
{
12+
13+
String graycode=Character.toString(binarycode.charAt(0));
14+
15+
16+
for(int i=0;i<binarycode.length()-1; i++)
17+
{
18+
19+
if(binarycode.charAt(i)==binarycode.charAt(i+1))
20+
graycode=graycode+"0";
21+
else
22+
graycode=graycode+"1";
23+
24+
}
25+
26+
return graycode;
27+
28+
}
29+
30+
}

0 commit comments

Comments
 (0)