[英]Addition of an integer with an hex string
What should I do to add an integer to an hex string. 我应该怎么做才能将整数添加到十六进制字符串。
Say my hex string is: 说我的十六进制字符串是:
11'h000
And I want to add integer 7 to it. 我想在其中添加整数7。 Output it should give should be
它应该给的输出应该是
11'h007
If given 11'h00e, Adding integer 1 to it should give me 11'h00f. 如果给定11'h00e,则将整数1添加为11'h00f。
Are there any predefined functions in c++? C ++中是否有任何预定义的函数? I could have write my switch-case statements to get it but looking for a compact way.
我本可以编写switch-case语句来获取它,但是正在寻找一种紧凑的方式。
The best way? 最好的方法? Don't confuse formatting of a number with a number.
不要将数字的格式与数字混淆。
Use 采用
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.