我是靠谱客的博主 朴素世界,这篇文章主要介绍C++之位测试练习的相关代码,现在分享给大家,希望可以做个参考。

## 位测试相关代码

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream> #include <stdio.h> #include <arpa/inet.h> using namespace std; typedef unsigned int UINT32; typedef union { struct Color{ UINT32 end:6; UINT32 b:8; UINT32 g:8; UINT32 r:8; UINT32 type: 2; } color; UINT32 data; } ColorData; #define TYPE_LEN 2 #define R_LEN 8 #define G_LEN 8 #define B_LEN 8 #define END_LEN 6 UINT32 formColor(UINT32 type,UINT32 r,UINT32 g,UINT32 b,UINT32 end){ printf("type:t%un",type << 30); printf("r:t%un",r << 22); printf("g:t%un",g << 14); printf("b:t%un",b << 6); return (type << 30) + (r << 22) + (g << 14) + (b << 6) + (end); } bool isBigEndian(){ int x = 1; char * p = (char *)&x; if(*p == 1) return false; else return true; } int main(){ ColorData gColorData; UINT32 col = formColor(2,60,60,60,20); gColorData.data = col; printf("htonl:t%dn",col); printf("Endian-Mode:%dn",isBigEndian()); printf("colordata:t%un",col); printf("==============================================n"); printf("type:t%dn",gColorData.color.type); printf("r:t%dn",gColorData.color.r); printf("g:t%dn",gColorData.color.g); printf("b:t%dn",gColorData.color.b); printf("end:t%dn",gColorData.color.end); printf("==============================================n"); return 0; }


最后

以上就是朴素世界最近收集整理的关于C++之位测试练习的相关代码的全部内容,更多相关C++之位测试练习内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(91)

评论列表共有 0 条评论

立即
投稿
返回
顶部