根据visual basic .net中的数据类型为变量赋值

时间:2016-08-02 04:19:00

标签: vb.net

我知道我的问题与此问题类似:Hex-Value in Visual Basic

但我想问的是更多细节。我的问题是:

如何根据VB中的数据类型为变量分配十六进制值?
例如,这些是分配我知道的格式的方法:

Dim arr_ui as UInteger() = {&HABCDEF01UI, &HABCDEF01UI} '32 bit unsigned integer
Dim arr as Integer() = {&HABCDEF01, &HABCDEF01}         '32 bit signed integer
Dim arr_64 as Int64() = {&HABCDEF01&, &HABCDEF01&}      '64 bit signed integer

这样就回到了我的问题,如何分配这些咒语:
- 无符号64位整数
- 有符号和无符号16位整数
- 有符号和无符号8位整数

提前致谢

2 个答案:

答案 0 :(得分:0)

' unsinged 64 bit integer
Dim uLong As ULong = &H123UL

' singed and unsigned 16 bit integer
Dim uShort As UShort = &H123US
Dim sShort As Short = &H123S

' signed and unsiged 8 bit integer:
' byte and signed byte won't have a suffix in VB.NET.
Dim aByte As Byte = &H12
Dim aSByte As SByte = &H11

答案 1 :(得分:-1)

因为jmcilhinney不想要求他的功劳,答案就在这里人们https://msdn.microsoft.com/en-us/library/s9cz43ek.aspx

以下是一些例子:

Dim a As Short = &H8000S    -- 16 bit signed
Dim b As UShort = &H8000US  -- 16 bit unsigned
Dim c As Short = &H8000I    -- 32 bit signed
Dim d As UShort = &H8000UI  -- 32 bit unsigned
Dim e As Short = &H8000L    -- 64 bit signed
Dim f As UShort = &H8000UL  -- 64 bit unsigned

替代方法:

Dim g As Short = &H8000%    -- 32 bit signed
Dim h As Short = &H8000&    -- 64 bit signed