Convert decimal to gray code in java

后端 未结 2 1044
深忆病人
深忆病人 2021-01-29 03:41

Had a question come up recently which was: write the algorithm to convert a decimal number to an n-bit gray code.

So for example: Using 1-bit (simplest):



        
2条回答
  •  渐次进展
    2021-01-29 04:38

    I was working in a different mathematical field. Unintentionally, I discovered two ways to convert numbers to Gray code. Example. From right to left: I make the divisions of 173 (8 digits in binary system) with the numbers 2,4,8,16,32, ..., 256. I round each quotient to the nearest integer. I am writing this integer down from the corresponding fraction. If this integer is even, then I write below this digit 0, otherwise I write the digit 1. These digits form the Gray Code of 173.

    Faster method. I can convert all numbers that have equal lengths of digits in the binary system to Gray codes. I do this without turning any number into binary. Here I find it difficult to present this method because it contains graphs, but you can find this here:

    http://viXra.org/abs/2004.0456?ref=11278286

提交回复
热议问题