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

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

问题描述

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

...似乎有点奇怪.

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

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