如何交换半字节用C? [英] How to swap nybbles in C?

查看:303
本文介绍了如何交换半字节用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何交换数字的半字节位位置?

How to swap the nybble bit positions of a number?

例如:534,将其转换成二进制,最右边的4位必须与最左边的4位互换,然后作出一个新的数字与

For example: 534, convert it into binary, the rightmost 4 bits has to be interchanged with the leftmost 4 bits and then make a new number with that.

任何人都知道如何做到这一点?

Anyone know how to do this?

推荐答案

这是一个事实,即十六进制 0xF的正好覆盖四位启动。中有16位数字四半字节。为啃的面具 0xf000 0xf00 0XF0 0xF的。然后开始屏蔽,移位和按位的OR-ing。

Start from the fact that hexadecimal 0xf covers exactly four bits. There are four nibbles in a 16-bit number. The masks for the nibbles are 0xf000, 0xf00, 0xf0, and 0xf. Then start masking, shifting and bitwise OR-ing.

这篇关于如何交换半字节用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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