如何将字节转换为负数 [英] How to convert byte to negative

查看:522
本文介绍了如何将字节转换为负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim m(5), x(5) As Byte
        For i As Integer = 0 To 4
            m(i) = i
        Next
        x(2) = -m(4)'Here it shows error
        MsgBox(x(2))




x(2)= -m(4)处的行显示错误. :-O
有什么方法可以将字节值转换为等效的-ve并将其存储在另一个字节变量中????




The line at x(2) = -m(4) shows an Error. :-O
Is there any method to convert a byte value to it''s -ve equivalent and store it in another byte variable????

推荐答案

.
字节是未签名的数据类型(字节上的MSDN [ ^ ])
由于没有符号,因此不能为负!

将来,也请发布错误消息-它可以帮助我们找出您遇到的困难.
You can''t.
Byte is an UNSIGNED data type (MSDN on Byte[^])
Since it has no sign, it cannot be negative!

In future, post the error message as well - it helps us to work out what you are having difficulties with.


您可以将其强制转换为int或short,然后翻转符号-但是您需要稍微更改一下设计以适应非字节存储.
You can cast it to an int or a short, then flip the sign - but you''d need to change your design a little to accommodate for non-byte storage.


谢谢大家,我已经将它简化了,而且效果很好

:cool :: cool :: cool :: cool :: cool:
Thanks Everyone I have casted it to short and it works great

:cool::cool::cool::cool::cool:


这篇关于如何将字节转换为负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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