Julia support following integer types.
Type
|
Number of Bits
|
Minimum value
|
Maximum value
|
Int8
|
8
|
-128
|
127
|
UInt8
|
8
|
0
|
255
|
Int16
|
16
|
-32768
|
32767
|
UInt16
|
16
|
0
|
65535
|
Int32
|
32
|
-2147483648
|
2147483647
|
UInt32
|
32
|
0
|
4294967295
|
Int64
|
64
|
-2^63
|
2^63 - 1
|
UInt64
|
64
|
0
|
2^64 - 1
|
Int128
|
128
|
-2^127
|
2^127 - 1
|
UInt128
|
128
|
0
|
2^128 - 1
|
Bool
|
8
|
false(0)
|
true(1), Any non zero value considered
as true.
|
All the integer types that prefixed with
‘U’ are unsigned (Only positive) numbers.
What
is the default type for integers?
It depends on target system architecture
(32 bit (or) 64 bit).
# 32-bit system: julia> typeof(100) Int32 # 64-bit system: julia> typeof(100) Int64
How
to know whether target system is 32-bit (or) 64-bit?
Julia provides a built-in constant 'WORD_SIZE', it returns the standard word size on the current machine, in bits.
Julia provides a built-in constant 'WORD_SIZE', it returns the standard word size on the current machine, in bits.
julia> WORD_SIZE 64
What
are the types Int, UInt?
In addition to the types mentioned in
table, Julia provides two more types that are just aliases to system default
integer and unsigned integer types.
#On 64-bit machine julia> Int Int64 julia> UInt UInt64 #On 32 bit machine julia> Int Int32 julia> UInt UInt32
Define
integers in hexadecimal notation
By prefixing a number with 0x, you can
define hexadecimal integers.
julia> a=0x12 0x12 julia> a 0x12 julia> dec(a) "18"
Define
integers in binary notation
By prefixing a number with 0b, you can
define binary integers.
julia> 0b1010 0x0a julia> dec(0b1010) "10"
Define
integers in octal notation
By prefixing a number with 0o, you can define binary integers.
By prefixing a number with 0o, you can define binary integers.
julia> 0o10 0x08 julia> dec(0o10) "8" julia> dec(0o14) "12"
No comments:
Post a Comment