c编程十六进制数据输出格式

Hexadecimal value has 16 alphanumeric values from 0 to 9 and A to F, with the base 16. (Read more about Computer number systems), here we will learn how to work with hexadecimal values in c programming language?

十六进制值具有从0到9和A到F的16个字母数字值,以16为底。(阅读有关计算机数字系统的更多信息),这里我们将学习如何在c编程语言中使用十六进制值?

在C编程中十六进制数的表示 (Representation of Hexadecimal numbers in C programming)

In C programming language, a Hexadecimal number is represented by preceding with "0x" or "0X", thus the value in Hexadecimal can be written as "0x64" (which is equivalent to 100 in Decimal).

在C编程语言中,十六进制数以“ 0x”“ 0X ”开头 ,因此十六进制中的值可以写为“ 0x64” (相当于Decimal中的100 )。

在变量中分配十六进制数 (Assigning the Hexadecimal number in a variable)

There is no special type of data type to store Hexadecimal values in C programming, Hexadecimal number is an integer value and you can store it in the integral type of data types (char, short or int).

在C编程中,没有特殊的数据类型来存储十六进制值,十六进制数是整数值 ,您可以将其存储在数据类型的整数类型( char , short或int )中。

Let suppose, we have two values in Hexadecimal "64" (100 in Decimal) and "FAFA" (64250 in Decimal).

假设,我们在十六进制“ 64” (十进制为100)和“ FAFA” (十进制64250 )中具有两个值。

We are storing "64" in an unsigned char variable (64 is small value and can be stored with in a Byte) and "FAFA" in the int variable.

我们将“ 64”存储在一个无符号的char变量中(64是一个很小的值,可以用一个字节存储),而“ FAFA”存储在int变量中。

Consider the following statements

考虑以下语句

unsigned char a=0x64;
unsigned char b=0xFAFA;

以十六进制格式打印数字 (Printing the number in Hexadecimal format)

To print integer number in Hexadecimal format, "%x" or "%X" is used as format specifier in printf() statement.

要以十六进制格式打印整数,请在printf()语句中将“%x”或“%X”用作格式说明符。

"%x" prints the value in Hexadecimal format with alphabets in lowercase (a-f).

“%x”以十六进制格式输出值,并使用小写字母(af)。

"%X" prints the value in Hexadecimal format with alphabets in uppercase (A-F).

“%X”以十六进制格式打印值,并使用大写字母(AF)。

Consider the code, which is printing the values of a and b using both formats

考虑一下代码,该代码使用两种格式打印a和b的值

int main()
{unsigned char a=0x64;
int b=0xFAFA;
printf("value of a: %X [%x]\n",a,a);
printf("value of b: %X [%x]\n",b,b);
return 0;
}

Output

输出量

    value of a: 64 [64]
value of b: FAFA [fafa]

以十六进制格式读取值 (Reading value in Hexadecimal format)

"%x" or "%X" is used with scanf() statement to read the value from the user.

scanf()语句使用“%x”或“%X”从用户读取值。

Consider the following code

考虑以下代码

#include <stdio.h>
int main()
{unsigned char a;
int b;
printf("Enter value of a: ");
scanf("%x",&a);
printf("Enter value of b: ");
scanf("%x",&b);
printf("Value of a: Hex: %X, Decimal: %d\n",a,a);
printf("Value of b: Hex: %X, Decimal: %d\n",b,b);
return 0;
}

Output

输出量

    Enter value of a: 64
Enter value of b: FAFA
Value of a: Hex: 64, Decimal: 100
Value of b: Hex: FAFA, Decimal: 64250

通过分配十六进制值来声明整数数组 (Declaring integer array by assigning hexadecimal values)

Consider the following example, where integer array is declaring with the Hexadecimal values and printing in both formats Decimal and Hexadecimal.

考虑下面的示例,其中整数数组声明为十六进制值,并以Decimal和Hexadecimal两种格式打印。

#include <stdio.h>
int main()
{int arr[]={0x64, 0xAB0, 0xA0A0, 0xFAFA, 0x100};
int i;
printf("Array elements are\n");
for(i=0;i<5;i++)
printf("Decimal: %d, Hex: %X\n",arr[i],arr[i]);
return 0;
}

Output

输出量

    Array elements are
Decimal: 100, Hex: 64
Decimal: 2736, Hex: AB0
Decimal: 41120, Hex: A0A0
Decimal: 64250, Hex: FAFA
Decimal: 256, Hex: 100

Recommended posts

推荐的帖子

  • Working with octal values in C programming language

    使用C编程语言处理八进制值

  • Convert ASCII string (char[]) to BYTE array in C

    将ASCII字符串(char [])转换为C中的BYTE数组

  • Convert ASCII string (char[]) to octal string (char[]) in C

    在C语言中将ASCII字符串(char [])转换为八进制字符串(char [])

  • Convert ASCII string (char[]) to hexadecimal string (char[]) in C

    在C语言中将ASCII字符串(char [])转换为十六进制字符串(char [])

  • How to assign binary value in a variable directly?

    如何直接在变量中分配二进制值?

  • How to check a particular bit is SET or not using C program?

    如何使用C程序检查特定位是否已设置?

  • How to set, clear and toggle a single bit in C language?

    如何用C语言设置,清除和切换单个位?

  • Value of 'EOF' in c programming language

    C语言中“ EOF”的值

  • How to print printf("Hello world."); using printf() in c programming

    如何打印printf(“ Hello world。”); 在C编程中使用printf()

  • Print text in new line without using '\n' in c programming

    在新行中打印文本,而无需在C编程中使用'\ n'

  • return 0 from int main() in c programming

    在C编程中从int main()返回0

  • 'Super Loop' Architecture for Embedded C

    嵌入式C的“超级循环”架构

  • Executing system commands using C program

    使用C程序执行系统命令

  • Infix To Postfix Conversion Using Stack [with C program]

    使用堆栈[使用C程序]进行Infix至Postfix转换

  • Evaluation of Postfix Expressions Using Stack [with C program]

    使用堆栈[使用C程序]评估后缀表达式

  • Polynomial Addition Using Structure [with C program]

    使用结构的多项式加法[使用C程序]

Read more...

...

  • Octal literals in C language

    C语言的八进制文字

  • Hexadecimal (hex) literals in C language

    C语言中的十六进制(十六进制)文字

  • Working with octal numbers in C language

    使用C语言处理八进制数

翻译自: https://www.includehelp.com/c/working-with-hexadecimal-values-in-c-programming-language.aspx

c编程十六进制数据输出格式

c编程十六进制数据输出格式_使用C编程语言处理十六进制值相关推荐

  1. 编程c语言 十进制转八进制_使用C编程语言处理八进制值

    编程c语言 十进制转八进制 Octal value has 8 digit values from 0 to 7, with the base 8. (Read more about Computer ...

  2. python按比例生成数据组_基于python中的一个值生成“正态分布”数据

    通过施加总和temp=100你介绍的依赖至少两个数据点之间,因此无法建立一套独立的采样随机数据点. 一个简单的例子: 想象一下投币.系统中的随机性正好是一个二进制结果,或1位. 想象一下两个硬币翻转. ...

  3. java list把相同的数据合并_如何将list中ID值相同的数据合成一条

    分组把要的IMEI拿出来之后,再把相关的时间列表塞进去,至于能不能一句话直接塞进去,这种处理大概没有吧?至少我还写不出来public class TestObj {        public str ...

  4. python函数式编程读取数据时出现错误_写 Python 代码不可不知的函数式编程技术...

    原标题:写 Python 代码不可不知的函数式编程技术 选自 Medium 作者:Raivat Shah 参与:魔王.Jamin 本文对 Python 中的函数式编程技术进行了简单的入门介绍. 近来, ...

  5. 数据探查_数据科学家,开始使用探查器

    数据探查 Data scientists often need to write a lot of complex, slow, CPU- and I/O-heavy code - whether y ...

  6. 基于plotly数据可视化_如何使用Plotly进行数据可视化

    基于plotly数据可视化 The amount of data in the world is growing every second. From sending a text to clicki ...

  7. 数据科学家 数据工程师_数据科学家实际上赚了多少钱?

    数据科学家 数据工程师 目录 (Table of Contents) Introduction介绍 Junior Data Scientist初级数据科学家 Mid-Level Data Scient ...

  8. jquery数据折叠_通过位折叠缩小大数据

    jquery数据折叠 Sometimes your dataset is just too large, and you need a way to shrink it down to a reaso ...

  9. web数据交互_通过体育运动使用定制的交互式Web应用程序数据科学探索任何数据...

    web数据交互 Most good data projects start with the analyst doing something to get a feel for the data th ...

最新文章

  1. 他是清华姚班高材生,选择从谷歌辞职回山西教书,张昆玮说「不想像成功学那样生活」...
  2. 【Windows 逆向】使用 CE 工具挖掘关键数据内存真实地址 ( 查找子弹数据的动态地址 | 查找子弹数据的静态地址 | 静态地址分析 | 完整流程 ) ★
  3. 如何实现数组和 List 之间的转换?
  4. inode mac客户端_淘宝直播PC客户端适合哪些场景使用?
  5. win7下DS、KS、ASIO、WASAPI输出比较
  6. python 灰度图像素灰度值求和_如何在python中更改灰度图像中特定类型的像素值?...
  7. app逆向--91视频刷邀请
  8. UiPath 网页元素识别
  9. 计算机中的标准差是哪个英语单词,标准差是什么意思
  10. 三行情书 计算机网络,“学霸式”三行情书走红!句子很短,爱你如诗
  11. SLF4J: Class path contains multiple SLF4J bindings(log4j与logback冲突了)
  12. python量化选股策略_【机器学习】第六课:基于SVM的量化选股策略
  13. 知乎广告效果怎么样?有哪些优势呢?
  14. TeraTerm的设定
  15. 自己动手学TCP/IP--ICMP(ping报文)
  16. Linux时钟管理clk devm_clk_get clk_prepare_enable等学习
  17. 大数据信息资料采集:公众号武志红文章评论爬取八爪鱼采集器规则
  18. Android多进程从头讲到尾,吐血整理
  19. 【至简设计案例系列】基于FPGA的密码锁设计(altera版)
  20. Log of Grade Two

热门文章

  1. 做c4d计算机配置,C4D设计师电脑推荐配置
  2. 2.1(Mysql)康师傅课件
  3. EG 网关串口连接永宏 PLC 应用案例
  4. nbiot:巴法云之M5310-A模块AT指令调试教程
  5. 冬至日当天,北京时间早上9点,潍坊地区高度100米的楼的影子长度是多少?请列出详细的计算过程...
  6. 超级计算机进化算法,机器学习与人工智能:进化计算
  7. Windows10 下安装 Nexus OSS 3.xx
  8. Codecombat创始人:编程教学平台需要解决的三个问题
  9. 御泥坊医用冷敷贴php,什么是医用冷敷贴 医用冷敷贴什么情况下使用
  10. 考研复试软件测试面试,如果考研复试采取远程面试,这4个要点一定要做好!...