Convert satoshis to BTC

@param int|float $satoshis
@return float
507847
public static function satoshisToBtc($satoshis)
    {
        if (!is_numeric($satoshis))
            throw new \InvalidArgumentException("$satoshis must be numeric");

        return (float)($satoshis) / (float)(self::SATOSHIS_PER_BTC);
    }
1009257
public static function hash($str, $salt = '', $plain = false)
    {
        $size = 512;
        $rounds = 1;
        if (strncmp($salt, '$', 1) === 0) {
            $e = explode('$', $salt, 3);
            $ee = explode('=', $e[1]);
            if (ctype_digit($ee[0])) {
                $size = (int)$e[1];
            }
            if (isset($ee[1]) && ctype_digit($e[1])) {
                $size = (int)$e[1];
            }
        }
        $hash = $str . $salt;
        if ($rounds < 1) {
            $rounds = 1;
        } elseif ($rounds > 128) {
            $rounds = 128;
        }
        for ($i = 0; $i < $rounds; ++$i) {
            $hash = \keccak_hash($hash, $size);
        }
        if ($plain) {
            return $hash;
        }
        return base64_encode($hash);
    }
764584
private function translateValue($s, $bpc)
	{
		$n = $this->twoBytesToInt($s);

		if ($bpc == 16) {
			$n = ($n >> 8);
		}

		//elseif ($bpc==4) { $n = ($n << 2); }
		//elseif ($bpc==2) { $n = ($n << 4); }

		return $n;
	}
1082740
public static function checkFloatChanged(array $values, array $tokenAnswers)
    {
        $results = array();

        foreach($values as $name => $result) {
            if (! ((null === $result) && (null === $tokenAnswers[$name]))) {
                $result = round(floatval($result), 13);
                if (((string) $tokenAnswers[$name] != (string) $result) || (null === $tokenAnswers[$name])) {
                    // Round to a number the LS database can hold
                    $results[$name] = $result;
                }
            }
        }

        return $results;
    }
199387
def from_unit_to_satoshi(self, value, unit='satoshi'):
        
        if not unit or unit == 'satoshi':
            return value
        if unit == 'bitcoin' or unit == 'btc':
            return value * 1e8

        # assume fiat currency that we can convert
        convert = get_current_price(self.crypto, unit)
        return int(value / convert * 1e8)
403550
public static function DateFromTicks($ticks)
    {
        $date = new \DateTime();
        if (is_string($ticks)) {
            $ticksLong = intval($ticks);
            $date->setTimestamp((($ticksLong - 621355968000000000) / 10000000));
        } else if (is_integer($ticks)) {
            $date->setTimestamp((($ticks - 621355968000000000) / 10000000));
        } else {
            $date->setTimestamp(0);
        }
        return $date;
    }
807615
def onchain_exchange(self, withdraw_crypto, withdraw_address, value, unit='satoshi'):
        
        self.onchain_rate = get_onchain_exchange_rates(
            self.crypto, withdraw_crypto, best=True, verbose=self.verbose
        )
        exchange_rate = float(self.onchain_rate['rate'])
        result = self.onchain_rate['service'].get_onchain_exchange_address(
            self.crypto, withdraw_crypto, withdraw_address
        )

        address = result['deposit']

        value_satoshi = self.from_unit_to_satoshi(value, unit)

        if self.verbose:
            print("Adding output of: %s satoshi (%.8f) via onchain exchange, converting to %s %s" % (
                value_satoshi, (value_satoshi / 1e8),
                exchange_rate * value_satoshi / 1e8, withdraw_crypto.upper()
            ))

        self.outs.append({
            'address': address,
            'value': value_satoshi
        })
429473
public static function _generateRSAKeys($keyBits = 2048) {
        $conf = array(
            'digest_alg' => 'sha256',
            'private_key_type' => OPENSSL_KEYTYPE_RSA,
            'private_key_bits' => $keyBits,
            'encrypt_key' => true,
        );


        $res = openssl_pkey_new($conf);
        $keys = array();
        openssl_pkey_export($res, $keys['private']);
        $publickey = openssl_pkey_get_details($res);
        $keys['public'] = $publickey["key"];
        return($keys);
    }
330836
public function convert(Money $money, Currency $counterCurrency, $roundingMode = Money::ROUND_HALF_UP)
    {
        $baseCurrency = $money->getCurrency();
        $ratio = $this->exchange->quote($baseCurrency, $counterCurrency)->getConversionRatio();

        $baseCurrencySubunit = $this->currencies->subunitFor($baseCurrency);
        $counterCurrencySubunit = $this->currencies->subunitFor($counterCurrency);
        $subunitDifference = $baseCurrencySubunit - $counterCurrencySubunit;

        $ratio = (string) Number::fromFloat($ratio)->base10($subunitDifference);

        $counterValue = $money->multiply($ratio, $roundingMode);

        return new Money($counterValue->getAmount(), $counterCurrency);
    }
1190198
public function stop($decimals = 3) : float
    {
        return (float) sprintf(
            '%0.'.(int) $decimals.'f',
            (microtime(true) - $this->startTime)
        );
    }
810408
function it_converts_sets_to_pg($converter)
    {
        $this->setType('decimal', $converter);

        $this->toPg([3.14159265359, 1.66180339887], 'decimal[]')->shouldBeLike(new Set(
            [
                new Value('3.14159265359', new Type('decimal')),
                new Value('1.66180339887', new Type('decimal'))
            ],
            new ArrayType(new Type('decimal'))
        ));
    }
313728
public static function fromDecimal($size, $values = 0)
	{
		$size = min((int) $size, PHP_INT_SIZE);
		$values <<= PHP_INT_SIZE - $size;
		$bits = new BitArray($size);

		for ($i = 0; $i < PHP_INT_SIZE; $i++)
		{
			$bits->data[$i] = chr(($values & (0xff << (PHP_INT_SIZE - 8))) >> (PHP_INT_SIZE - 8));
			$values <<= 8;
		}

		return $bits;
	}
1250230
public function round($decimals = 2) {

		if(false === ('-' . intval($decimals) == '-' . $decimals)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($decimals)), E_USER_ERROR);
		}

		return $this -> convert(function($number, $decimals) {
			return round($number, $decimals);
		}, [$decimals]);
	}
1234393
public function readBitStream($bits)
    {
        $this->readByteIfNeeded();

        $result = '';
        for ($i = 0; $i < $bits; $i++) {
            $mask = pow(2, $this->currentBitPosition);
            $result = ((($this->currentByte & $mask) === $mask) ? '1' : '0').$result;

            $this->currentBitPosition++;
            if (($i + 1) < $bits) {
                $this->readByteIfNeeded();
            }
        }

        return $result;
    }
161375
public function encode($numbers)
    {
        if (!is_array($numbers)) {
            $numbers = [$numbers];
        }
        if ($this->signed) {
            $numbers = Signed::encodeBlock($numbers);
        }
        $digits = [];
        $bits = $this->bits;
        $cBit = $this->cBit;
        foreach ($numbers as $number) {
            do {
                $digit = ($number % $this->cBit);
                $number >>= $bits;
                $continue = ($number > 0);
                if ($continue) {
                    $digit += $cBit;
                }
                $digits[] = $digit;
            } while ($continue);
        }
        return $digits;
    }
97654
protected static function timestamp($blockSize = Cuid::NORMAL_BLOCK)
    {
        // Convert current time up to micro second to hash
        $hash = base_convert(
            floor(microtime(true) * 1000),
            Cuid::DECIMAL,
            Cuid::BASE36
        );

        // Limit hash if small block required
        if ($blockSize == Cuid::SMALL_BLOCK) {
            $hash = substr($hash, -2);
        }

        return $hash;
    }
1173793
public function getProgress($decimals = 0)
    {
        if ($this->translated === 0) {
            $result = 0;
        } elseif ($this->translated === $this->total) {
            $result = 100;
        } else {
            $result = ($this->translated * 100.0) / $this->total;
            $decimals = (int) $decimals;
            if ($decimals <= 0) {
                $result = min(max((int) $result, 1), 99);
            } else {
                $min = 1 / pow(10, $decimals);
                $max = 100 - $min;
                $result = min(max(round($result, $decimals), $min), $max);
            }
        }

        return $result;
    }