繁体   English   中英

带十六进制字符串的整数加法

[英]Addition of an integer with an hex string

我应该怎么做才能将整数添加到十六进制字符串。

说我的十六进制字符串是:

11'h000

我想在其中添加整数7。 它应该给的输出应该是

11'h007

如果给定11'h00e,则将整数1添加为11'h00f。

C ++中是否有任何预定义的函数? 我本可以编写switch-case语句来获取它,但是正在寻找一种紧凑的方式。

最好的方法? 不要将数字的格式与数字混淆。

采用

int x = std::stoi(s/*a hexadecimal string*/, nullptr, 16 /*hexadecimal*/);
x++; /*all your arithmetic operations here*/
std::cout/*or a suitable stream*/ << std::hex << x;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM