Convertion of grey code and binary 格雷码和二进制数之间的转换
2015-03-05 13:40
330 查看
以下转换代码摘自维基百科 Wikipedia:
/* The purpose of this function is to convert an unsigned binary number to reflected binary Gray code. The operator >> is shift right. The operator ^ is exclusive or. */ unsigned int binaryToGray(unsigned int num) { return (num >> 1) ^ num; } /* The purpose of this function is to convert a reflected binary Gray code number to a binary number. */ unsigned int grayToBinary(unsigned int num) { unsigned int mask; for (mask = num >> 1; mask != 0; mask = mask >> 1) { num = num ^ mask; } return num; }
相关文章推荐
- Lintcode: Binary Tree Serialization (Serialization and Deserialization Of Binary Tree)
- 格雷码(Gray)和二进制(Binary)之间的相互转换
- Lintcode - Serialization and Deserialization Of Binary Tree
- 【Team Homework 5】翻译Software Engineering Code of Ethics and Professional Practice的序言
- 用汇编实现格雷码与二进制数的转换
- Action and Func<object> 之间的转换.
- 递归交换二叉树左右子树:BinaryTree:Exchange the left child and right child of a binary tree
- 音乐频谱显示 FFT of waveIn audio signals. Free source code and programming help
- Xcode code sense and cmd+click to symbol doesn't work for 1 of my projects
- Conversion Between Unicode-UCS-4 And UTF-8 (Unicode-UCS-4 与 UTF-8 之间的转换)
- The Hopes of Agnes Grey Contrasted with the Reality ---- Discussion on the Distance between Ideality and Reality
- OpenCv,EmguCv及.net之间的互动(The Interaction of OpenCv, EmguCv AND .net)
- Adding and extracting binary resources[www.codeproject.com]
- Zen Coding — a new way of writing HTML and CSS code
- 字符集之间转换(UTF-8,UNICODE,Gb2312)c++and java
- Software Engineering Code of Ethics and Professional Practice 翻译:原则1和原则2
- ASP.NET MVC Code and Slides for Best of Mix 09 Presentation
- Call C# Code from C++ and read an array of struct which contains strings
- Verilog中状态机编码方式的选择:二进制编码(Binary)、格雷码(Gray-code)编码、独热码(One-hot)编码
- Corporation of cuda and openGL Texture( Source Code sample)