Add the getHex() method

This commit is contained in:
Ben Ramsey
2014-01-17 16:37:51 -06:00
parent 7850144c28
commit 2eaf153ce4
+12 -8
View File
@@ -231,11 +231,8 @@ final class Uuid
{
$bytes = '';
$hex = $this->toString();
$hex = str_replace('-', '', $hex);
foreach (range(-2, -32, 2) as $step) {
$bytes = chr(hexdec(substr($hex, $step, 2))) . $bytes;
$bytes = chr(hexdec(substr($this->getHex(), $step, 2))) . $bytes;
}
return $bytes;
@@ -423,6 +420,16 @@ final class Uuid
return $this->fields;
}
/**
* Returns the hexadecimal value of the UUID
*
* @return string
*/
public function getHex()
{
return str_replace('-', '', $this->toString());
}
/**
* Returns the integer value of the UUID, represented as a BigNumber
*
@@ -440,11 +447,8 @@ final class Uuid
);
}
$hex = $this->toString();
$hex = str_replace('-', '', $hex);
$number = \Moontoast\Math\BigNumber::baseConvert(
$hex,
$this->getHex(),
16,
10
);