Commit BinaryToGray
This commit is contained in:
parent
39806e3fe6
commit
91c19921ef
30
src/main/java/com/conversions/BinaryToGray.java
Normal file
30
src/main/java/com/conversions/BinaryToGray.java
Normal file
@ -0,0 +1,30 @@
|
||||
package src.main.java.com.conversions;
|
||||
|
||||
public class BinaryToGray
|
||||
{
|
||||
/* This method convert the binary number into gray code
|
||||
@param binaryno need to convert binary number into gray code
|
||||
@return graycode return as string
|
||||
*/
|
||||
|
||||
public String binaryToGray(String binarycode)
|
||||
{
|
||||
|
||||
String graycode=Character.toString(binarycode.charAt(0));
|
||||
|
||||
|
||||
for(int i=0;i<binarycode.length()-1; i++)
|
||||
{
|
||||
|
||||
if(binarycode.charAt(i)==binarycode.charAt(i+1))
|
||||
graycode=graycode+"0";
|
||||
else
|
||||
graycode=graycode+"1";
|
||||
|
||||
}
|
||||
|
||||
return graycode;
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user