chore(i8n,learn): processed translations

This commit is contained in:
Crowdin Bot
2021-02-06 04:42:36 +00:00
committed by Mrugesh Mohapatra
parent 15047f2d90
commit e5c44a3ae5
3274 changed files with 172122 additions and 14164 deletions

View File

@ -1,64 +1,94 @@
---
id: 5a23c84252665b21eecc7e80
title: 格雷码
title: Gray code
challengeType: 5
videoUrl: ''
forumTopicId: 302276
dashedName: gray-code
---
# --description--
[格雷码](<https://en.wikipedia.org/wiki/Gray code>)是二进制编码的一种形式,其中连续数字之间的转换仅相差一位。这是一种有用的编码,用于减少硬件数据危险,其值快速变化和/或连接到较慢的硬件作为输入。从左到右或从上到下依次为[卡诺图](<https://en.wikipedia.org/wiki/Karnaugh map>)生成输入也很有用。创建一个函数来编码数字并解码格雷码中的数字。该函数应该有2个参数。第一个是布尔值。该函数应编码为true解码为false。第二个参数是要编码/解码的数字。显示所有5位二进制数的正常二进制表示格雷码表示和解码格雷码值0-31包括0不需要前导0。有许多可能的格雷码。以下编码所谓的“二进制反射格雷码”。
编码MSB为0位b为二进制g为格雷码 <code><br>if b[i-1] = 1<br><span style='padding-left:1em'>g[i] = not b[i]</span><br>else<br><span style='padding-left:1em'>g[i] = b[i]</span><br></code>要么:
`g = b xor (b logically right shifted 1 time)`
解码MSB为0位b为二进制g为格雷码
<code>b[0] = g[0]<br>for other bits:<br>b[i] = g[i] xor b[i-1]<br></code>
[Gray code](https://en.wikipedia.org/wiki/Gray code) is a form of binary encoding where transitions between consecutive numbers differ by only one bit.
This is a useful encoding for reducing hardware data hazards with values that change rapidly and/or connect to slower hardware as inputs.
It is also useful for generating inputs for [Karnaugh maps](https://en.wikipedia.org/wiki/Karnaugh map) in order from left to right or top to bottom.
# --instructions--
Create a function to encode a number to and decode a number from Gray code. The function should will have 2 parameters.
The first would be a boolean. The function should encode for true and decode for false. The second parameter would be the number to be encoded/decoded.
Display the normal binary representations, Gray code representations, and decoded Gray code values for all 5-bit binary numbers (0-31 inclusive, leading 0's not necessary).
There are many possible Gray codes. The following encodes what is called "binary reflected Gray code."
Encoding (MSB is bit 0, b is binary, g is Gray code):
<pre>if b[i-1] = 1
g[i] = not b[i]
else
g[i] = b[i]
</pre>
Or:
<pre>g = b xor (b logically right shifted 1 time)
</pre>
Decoding (MSB is bit 0, b is binary, g is Gray code):
<pre>b[0] = g[0]<br>
for other bits:
b[i] = g[i] xor b[i-1]
</pre>
# --hints--
`gray`应该是一个功能。
`gray` should be a function.
```js
assert(typeof gray == 'function');
```
`gray(true,177)`应该返回一个数字。
`gray(true,177)` should return a number.
```js
assert(typeof gray(true, 177) == 'number');
```
`gray(true,177)`应该返回`233`
`gray(true,177)` should return `233`.
```js
assert.equal(gray(true, 177), 233);
```
`gray(true,425)`应该返回`381`
`gray(true,425)` should return `381`.
```js
assert.equal(gray(true, 425), 381);
```
`gray(true,870)`应该返回`725`
`gray(true,870)` should return `725`.
```js
assert.equal(gray(true, 870), 725);
```
`gray(false,233)`应该返回`177`
`gray(false,233)` should return `177`.
```js
assert.equal(gray(false, 233), 177);
```
`gray(false,381)`应该返回`425`
`gray(false,381)` should return `425`.
```js
assert.equal(gray(false, 381), 425);
```
`gray(false,725)`应该返回`870`
`gray(false,725)` should return `870`.
```js
assert.equal(gray(false, 725), 870);