一起添加十六进制数 [英] Adding hex numbers together

查看:89
本文介绍了一起添加十六进制数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个代表十六进制数的2数字数组

index2 = 0x10

index1 = 0xD



有人可以告诉我如何组合这两个数字,这样我就可以得到十六进制值100D



i尝试以下代码







Hi if I got an array of 2 number that represent a hex number
index2 = 0x10
index1 = 0xD

can someone tell me how to combine these two numbers so i can get the hex value 100D

i try the below code



Dim index1, index2, result As Short

    index2 = &H10
    index1 = &HD

 

    result = index1 + (index2 < 8)

推荐答案

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


这篇关于一起添加十六进制数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆