What is the gmp_export() function in PHP?

Overview

The gmp_export() function in PHP converts the number to a binary string.

Syntax

gmp_export(GMP|int|string $num, int $word_size = 1, int $flags = GMP_MSW_FIRST | GMP_NATIVE_ENDIAN): string

Parameters

  • num: This is a GMP object, integer, or a string value to convert to a binary string.
  • word_size: This parameter indicates the number of bytes in a chunk of binary data. The default value is 1. This is dependent on the flags parameter.
  • flags: The default value is GMP_MSW_FIRST | GMP_NATIVE_ENDIAN.

Return value

The method returns a binary string.

Code

<?php
$bin = gmp_export(12343);
echo "gmp_export(12343) - ".$bin;
?>

Explanation

  • Line 2: We construct a gmp number using the gmp_init() method.
  • Line 3: We print the binary string.
Copyright ©2024 Educative, Inc. All rights reserved