为什么十进制数类型为Int64时,十六进制或二进制数为Uint64? [英] Why is typeof hex or binary number Uint64 while type of decimal number is Int64?

查看:48
本文介绍了为什么十进制数类型为Int64时,十六进制或二进制数为Uint64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

julia> typeof(-0b111)
Uint64

julia> typeof(-0x7)
Uint64

julia> typeof(-7)
Int64

我发现这个结果有点令人惊讶.为什么数字的数字底数决定带符号或不带符号?

I find this result a bit surprising. Why does the numeric base of the number determine signed or unsgined-ness?

推荐答案

这是预期的行为:

此行为基于以下观察结果:使用无符号时 整数值的十六进制文字,通常是使用它们来 代表固定的数字字节序列,而不只是整数 值.

This behavior is based on the observation that when one uses unsigned hex literals for integer values, one typically is using them to represent a fixed numeric byte sequence, rather than just an integer value.

http://docs.julialang .org/en/latest/manual/integers-and-floating-point-numbers/#integers

...似乎有点奇怪.

...seems like a bit of an odd choice.

这篇关于为什么十进制数类型为Int64时,十六进制或二进制数为Uint64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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