Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

c++ - Drawing up a hexadecimal number from several decimal numbers

I have a vector container. There are a number from 0 to 255. The data bytes are top (of the container). On the fourth day begins mantissa and it may consist of several numbers, for example. Mantissa consists of <120, 111, 200>. That is, it is the number of machine: <0x78, 0x6F, 0xC8>. Total turn mantissa: 0x786FC8.

I can convert because of the method:

  1. Set the number of 120, 111, 200 in hexadecimal.(0x78, 0x6F, 0xC8)
  2. Put the numbers in line.("78" "6F" "C8")
  3. Fold the line.("786FC8")
  4. Move back to an integer type. 0x786FC8

Q: Is there any way you do it faster and without strings?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It sounds like you want <120, 111, 200> → (120 * 256 + 111) * 256 + 200.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...