Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Julia: Represent Big integers


Julia provide BigInt(x) method to create an arbitrary precision integer.
julia> data=BigInt(123456789876543212345678987654321123456)
123456789876543212345678987654321123456

julia> data=data+1
123456789876543212345678987654321123457

julia> data=data+123456
123456789876543212345678987654321246913

julia> typeof(data)
BigInt

Convert String to BigInt
By using parse method a string can be converted to BigInt.

parse(type, str[, base])
Argument
Description
type
Represents the type to convert. Default base is 10.
str
String to convert. If string is not valid number, then error is raised.
base
Base is optional, for integer conversion default to 10.


julia> parse(BigInt,"123456789876543212345678987654321123456")
123456789876543212345678987654321123456

julia> parse(BigInt,"123456789876543212345678987654321123456",16)
6495562832392744988215426867090392857409893462


Convert String Literal to BigInt
By using big string literal form, you can convert a string literal to BigInt.
julia> x=big"100123456789876543212345678987654321123456"
100123456789876543212345678987654321123456

julia> typeof(x)
BigInt








Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Julia: Represent Big integers

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×