How to concatinate 3 ints into unsigned long long?

你离开我真会死。 提交于 2019-12-11 05:22:41

问题


Say, we get int A 333; int B 4444 and int C 5454 we want to concatenate them into one unsigned long long 000333 004444 005454 00 (with format like 0/1 int sign, int). How to do such formating in C++, and are there any C++11 tools that can simplify process?


回答1:


You could make strings from the ints using std::to_string, concatenate as necessary, then convert to long long using std::stoll.




回答2:


Do you just mean this?

unsigned int A = 333;
unsigned int B = 4444;
unsigned int C = 5454;

unsigned long long r = A*100000000000000ULL + B*100000000ULL + C*100ULL;

Proof it works: http://ideone.com/XWFdU



来源:https://stackoverflow.com/questions/11187898/how-to-concatinate-3-ints-into-unsigned-long-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!