首页Home › 文本工具Text Tools

🔁 二进制与格雷码互转Binary to Gray Code Converter

把二进制数转换为格雷码(反射二进制码),或把格雷码还原为二进制;每行一个,可同时显示十进制。用于编码器、卡诺图和数字电路。Convert binary numbers to Gray code (reflected binary) or Gray code back to binary, one per line, with optional decimal values — for rotary encoders, Karnaugh maps and digital logic.

使用说明与常见问题How-to & FAQ

「二进制与格雷码互转」是什么?What is the Binary to Gray Code Converter tool?

把二进制数转换为格雷码(反射二进制码),或把格雷码还原为二进制;每行一个,可同时显示十进制。用于编码器、卡诺图和数字电路。Convert binary numbers to Gray code (reflected binary) or Gray code back to binary, one per line, with optional decimal values — for rotary encoders, Karnaugh maps and digital logic.

如何使用「二进制与格雷码互转」?How do I use the Binary to Gray Code Converter tool?

在「二进制与格雷码互转」中,把内容粘贴或输入到上方输入框,结果会实时显示在下方,点击「复制结果」即可复制。例如输入「1010_1111」,得到「11111000」。In the Binary to Gray Code Converter: Paste or type into the input box; the result appears below instantly — click "Copy result" to copy it. Example: "1010_1111" → "11111000".

格雷码怎么算?How is Gray code computed?

二进制转格雷码:最高位不变,其余每一位等于二进制中该位与左边一位的异或(G = B XOR (B >> 1))。格雷码转二进制:最高位不变,之后每位等于上一位二进制结果与当前格雷码位的异或。Binary to Gray: keep the top bit, and each other bit is the XOR of that binary bit and the one to its left (G = B XOR (B >> 1)). Gray to binary: keep the top bit, then each bit is the XOR of the previous binary result bit and the current Gray bit.

格雷码有什么用?What is Gray code used for?

相邻两个数只有一位不同,可避免机械编码器、模数转换在跳变时读出错误中间值,也用于卡诺图排序和遗传算法。Neighbouring values differ in only one bit, which prevents rotary encoders and ADCs from reading wrong intermediate values during a transition. It is also used to order Karnaugh maps and in genetic algorithms.

位数会变吗?Does the bit length change?

不会,输出与输入位数相同,前导 0 会保留。非常长的二进制串也支持(逐位计算,十进制用 BigInt)。No. The output has the same number of bits and leading zeros are kept. Very long bit strings work too (bitwise, with BigInt for decimals).

括号里的十进制和空格分组是什么意思?What do the decimal note and spaces mean?

勾选“显示十进制值”后,每行后面显示“输入的十进制 → 输出的十进制”,如 1010 → 1111 显示为(十进制:输入 10 → 输出 15)。每行只算一个数:行内的空格和下划线(如 1010 1111、1_0_1)被当作分组符号忽略,并在结果下方提示;要转换多个数请分行输入。With 'Show decimal values' on, each line ends with the decimal value of the input and of the output, e.g. 1010 → 1111 shows (decimal: input 10 → output 15). Each line is one number: spaces and underscores inside it (1010 1111, 1_0_1) are ignored as digit grouping, with a notice below the result; put separate numbers on separate lines.

处理大段文本会卡吗?Can it handle long text?

「二进制与格雷码互转」在浏览器中直接处理,几 MB 以内的文本通常瞬间完成;文本不会离开你的设备。The Binary to Gray Code Converter runs in your browser; text up to a few MB is usually processed instantly and never leaves your device.

「二进制与格雷码互转」免费吗?需要注册吗?Is the Binary to Gray Code Converter free? Do I need an account?

「二进制与格雷码互转」完全免费,无需注册或安装,打开网页即可使用,手机和电脑都能用;输入的内容只在你的浏览器本地处理。The Binary to Gray Code Converter is completely free with no sign-up or install and works on phones and desktops; what you enter is processed only in your browser.

相关工具Related tools

🔀 字母打乱器(随机打乱字母/字符)Shuffle Letters🪞 镜像文字生成器(反向文字)Mirror Text Generator📝 在线记事本(自动保存)Online Notepad👻 隐形字符生成器(空白昵称/空消息)Invisible Text Generator🔢 字数统计Word & Character Counter🔠 大小写转换Case Converter🧹 删除重复行Remove Duplicate Lines↕️ 文本行排序Sort Lines🆚 文本对比Text Diff Checker🔍 文本查找替换Find and Replace Text🔗 URL Slug 生成器URL Slug Generator📄 假文生成器Lorem Ipsum Generator

← 全部工具All tools