Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
22
Task/Gray-code/JavaScript/gray-code-2.js
Normal file
22
Task/Gray-code/JavaScript/gray-code-2.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import printf from 'printf' // Module must be installed with npm first
|
||||
import * as gray from './gray-code.js'
|
||||
|
||||
console.log(
|
||||
'Number\t' +
|
||||
'Binary\t' +
|
||||
'Gray Code\t' +
|
||||
'Decoded Gray Code'
|
||||
)
|
||||
|
||||
for (let number = 0; number < 32; number++) {
|
||||
const grayCode = gray.encode(number)
|
||||
const decodedGrayCode = gray.decode(grayCode)
|
||||
|
||||
console.log(printf(
|
||||
'%2d\t%05d\t%05d\t\t%2d',
|
||||
number,
|
||||
number.toString(2),
|
||||
grayCode.toString(2),
|
||||
decodedGrayCode
|
||||
))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue