Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

OpenSSL::BN#to_s

() -> ::String
(0) -> ::String
(2) -> ::String
(10) -> ::String
(16) -> ::String
(::int base) -> ::String
bn.to_s(base = 10) → string

Returns the string representation of the bignum.

BN.new can parse the encoded string to convert back into an OpenSSL::BN.

base

The format. Must be one of the following:

  • 0 - MPI format. See the man page BN_bn2mpi(3) for details.

  • 2 - Variable-length and big-endian binary encoding. The sign of the bignum is ignored.

  • 10 - Decimal number representation, with a leading ‘-’ for a negative bignum.

  • 16 - Hexadecimal number representation, with a leading ‘-’ for a negative bignum.

See also #to_int #ucmp #to_i #zero? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0