在C / C ++有什么扭转位的一个字节的顺序最简单的方法? [英] In C/C++ what's the simplest way to reverse the order of bits in a byte?

查看:208
本文介绍了在C / C ++有什么扭转位的一个字节的顺序最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然有多种方式来扭转一个字节位顺序,我很好奇,什么是最简单的开发人员来实现。并通过扭转我的意思是:

While there are multiple ways to reverse bit order in a byte, I'm curious as to what is the "simplest" for a developer to implement. And by reversing I mean:

1110 -> 0111
0010 -> 0100

这是类似的,但不是这个 PHP的问题。

This is similar to, but not a duplicate of this PHP question.

此相似,但不<一个重复href=\"http://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c\">this Ç问题。这个问题是要求最简单的方法由开发人员来实现。涉及内存和CPU性能最好的算法。

This is similar to, but not a duplicate of this C question. This question is asking for the easiest method to implement by a developer. The "Best Algorithm" is concerned with memory and cpu performance.

推荐答案

如果你正在谈论一个字节,表查找可能是最好的选择,除非出于某种原因,你没有256字节可用做。

If you are talking about a single byte, a table-lookup is probably the best bet, unless for some reason you don't have 256 bytes available.

这篇关于在C / C ++有什么扭转位的一个字节的顺序最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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