ios - 按位右移 >> 在 Objective-C 中

标签 ios objective-c c bit-manipulation shift

我有一个变量 (unsigned int) part_1

如果我这样做: NSLog(@"%u %08x", part_1, part_1);(打印无符号值和十六进制值)输出:

2063597568 7b000000

(只有前两个有值)。

我想把它转换成

0000007b

所以我试过 unsigned int part_1b = part_1 >> 6(以及很多变体)

但是这个输出:

32243712 01ec0000

我哪里错了?

最佳答案

您想移动 6*4 = 24 位,而不仅仅是 6 位。十六进制 printf 中的每个“0”代表 4 位。

unsigned int part_1b = part_1 >> 24;
                                 ^^

关于ios - 按位右移 >> 在 Objective-C 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19794519/

相关文章:

ios - 无法构建 Xamarin iOS 项目

ios - CALayer 创建透明圆形 mask

iphone - 核心动画 : ignoring exception: *** -[NSPlaceholderString initWithString:]: nil argument

ios - UI 元素坐标到 UI 元素属性

iphone - MKStoreKit -isSubscriptionActive 总是返回 False

objective-c - 如何禁用(或收到通知)删除已加载的插件(NSBundle)文件?

c# - 如何在 Windows 7 下记录来自非标准按键的按键事件

ios - 向 UITextView 添加轮廓/描边

将matlab m文件转换为c文件

c - Entab 程序意外错误(读访问冲突)