字节ansi C中的反向位 [英] reverse bits in byte ansi C

查看:105
本文介绍了字节ansi C中的反向位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能可以反转字节中的位,但是我不理解语法.为什么使用0x0802U& 0x22110U和其他二进制操作(此数字是什么)

unsigned char reverse(unsigned char B)
{
return (unsigned char)(((b * 0x0802U & 0x22110U) | (b * 0x8020U & 0x88440U)) * 0x10101U >> 16);
}

解决方案

检查"Bit Twiddling Hacks"页面以获取解释:

通过7个操作(无64位)反转一个字节中的位 http://graphics.stanford.edu/~seander/bithacks.html

I have a function that reverse the bits in a byte but i don't understand the syntax. Why is used 0x0802U & 0x22110U and other binary operations(what are this numbers)

unsigned char reverse(unsigned char B)
{
return (unsigned char)(((b * 0x0802U & 0x22110U) | (b * 0x8020U & 0x88440U)) * 0x10101U >> 16);
}

解决方案

Check the "Bit Twiddling Hacks" page for the explanation:

Reverse the bits in a byte with 7 operations (no 64-bit) http://graphics.stanford.edu/~seander/bithacks.html

这篇关于字节ansi C中的反向位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆