长型最大HEX值 [英] Max HEX value for long type

查看:71
本文介绍了长型最大HEX值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Java代码移植到C#. 您能否解释一下为什么在以下行中出现编译时错误(我使用VS 2008):

I have ported Java code to C#. Could you please explain why I have compile-time error in the follow line (I use VS 2008):

    private long l = 0xffffffffffffffffL; // 16 'f' got here

无法将源类型ulong转换为目标类型long

我在这里需要与原始Java代码相同的值.

I need the same value here as for origin Java code.

推荐答案

假设您不担心负值,可以尝试使用

Assuming you aren't worried about negative values, you could try using an unsigned long:

private ulong l = 0xffffffffffffffffL;

在Java中,l的实际值应为-1,因为它会溢出2^63 - 1最大值,因此您只需将常量替换为-1.

In Java the actual value of l would be -1, because it would overflow the 2^63 - 1 maximum value, so you could just replace your constant with -1.

这篇关于长型最大HEX值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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