November 2017
Beginner
316 pages
6h 40m
English
We have used conversion in previous examples. Type conversion refers to changing the type of the variable, but keeping the value of the variable the same:
#creating a 8-bit Integerjulia> Int8(100)100#we will get an error here as we exceed the size of the Int8julia> Int8(100*10)ERROR: InexactError()in Int8(::Int64) at ./sysimg.jl:53#this is solved by using Int16julia> Int16(100*10)1000#create a variable x of type Int32julia> x = Int32(40); typeof(x)Int32#using type conversion, convert it to Int8julia> x = Int8(x); typeof(x)Int8
We were successful, as 40 is in the range of the signed Int8.
Read now
Unlock full access