且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一起添加十六进制数

更新时间:2023-11-08 11:17:40

Dim index1, index2, result As UShort
 
index2 = &H10
index1 = &HD
 
result = index1 + (index2 << 8)


你不可能有一个代表十六进制数的数字数组。您可以使用每个表示数字的字符串数组,但这不是数字数组。你可以有一组数字,但数字不能是十六进制或十进制。数字是一个数字,总是二进制。所以,这个问题根本没有意义。



如果你有字符串,你需要将每个字符串解析成一个数字并使用数字运算。如果您有数组,请对这些数字进行数值运算。你甚至没有解释你正在使用的语言和平台(我觉得有些人认为世界上只有一个平台和一种语言,你不是其中之一吗?:-)),所以不代码给你。你真的需要学习编程的一些基础知识,至少要获得提出更正确问题的技巧。



另外,如果你真的使用了字符串数组,那么这些日子会反映出许多初学者的巨大谬误:使用表示数据而不是数据本身的字符串的不良趋势。你应该尝试处理数据,而不是那些字符串。



-SA
You cannot possibly have an array of numbers representing HEX numbers. You can either have array of string each representing a number, but this is not an array of numbers. Of you can have an array of numbers, but a number cannot be "hex" or "decimal". A number is a number, always "binary". So, the question simply makes no sense.

If you have strings, you need to parse each as "hex" into a number and use numeric arithmetic. If you have array of numbers, do numeric arithmetic on these numbers. You did not even explain what language and platform you are using (I feel that some people think that there is only one platform and one language in the world, aren't you one of them? :-)), so not code for you. You really need to learn some basics of programming, at least to get the skill of asking more correct questions.

Also, if you really use the array of strings, it would reflect the great fallacy of many beginners these days: a bad trend to work with strings representing data instead of data itself. You should try to work with data, not those strings.

—SA