在变量中存储一个十六进制值(DIM XX为"六角")在VB.NET [英] Storing a hexadecimal value in a variable (Dim xx as "Hex") in VB.NET

查看:222
本文介绍了在变量中存储一个十六进制值(DIM XX为"六角")在VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何存储在变量中的十六进制数字没有它成为一个小数点?

How can I store a hexadecimal number in a variable without it becoming a decimal?

还是我的有无将其存储为一个字符串或整数?

Or do I have to store it as either a string or integer?

推荐答案

在.NET整数不存储为小数,它们被存储为二进制文件中的重新presentation。十进制和十六进制是reoresenting更人性化的方式的数量只是不同的方式。

Integers in .NET are not stored as decimal, they are stored as binary in two's complement representation. Both decimal and hexadecimal are just different ways of reoresenting the number in a more human-friendly way.

如果要输出一个数字为十六进制,你可以用x或X格式说明ToString方法(它的输出和较低分别为大写)以指定字符的可选固定数量的 N,其中n是字符数

If you want to output a number as hexadecimal you can use the "x" or "X" format specifier with the ToString method (which output lower- and upper-case respectively) with an optional fixed number of characters specified as "n" where n is the number of characters.

输出一个整数,为十六进制的一些例子:

Some examples of outputting an integer as hex:

Dim n as Integer = &HBEEF;
Console.WriteLine(n.ToString("x")) ' output in lower case, e.g. beef '
Console.WriteLine(n.ToString("X")) ' output in upper case, e.g. BEEF '
Console.WriteLine(n.ToString("X8")) ' upper case & 8 chars, e.g. 0000BEEF '

这篇关于在变量中存储一个十六进制值(DIM XX为"六角")在VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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