Bitcoin Little-Endian


Reading of little-endian is not friendly to human but friendly to computer. Most of fields in serialized transaction are in little-endian format.

Find Little-Endian

<?php 
use BitWasp\Buffertools\Buffer;

include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");

$result = '';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	try {
		if ($_POST['encoding']=='hex') {
			if (!ctype_xdigit($_POST['input'])) {
				throw new Exception('Input must be hex string.');
			}
			
			$bf = Buffer::hex($_POST['input']);
		} else {
			if (!ctype_digit($_POST['input'])) {
				throw new Exception('Input must be integer.');
			}
			
			$bf = Buffer::int($_POST['input']);
		}
		
		$result   = $bf->flip()->getHex();
	} catch (Exception $e) {
		$errmsg .= "Problem found. " . $e->getMessage();
	}
}

if ($errmsg) {
?>
	<div class="alert alert-danger">
		<strong>Error!</strong> <?php echo $errmsg?>
	</div>
<?php
}

if ($result) {
?>
	<div class="table-responsive">
		<table border=0 class='table'>
			<tr><td>Input</td><td><?php echo $_POST['input']?></td></tr>
			<tr><td>Input Encoding</td><td><?php echo ucfirst($_POST['encoding'])?></td></tr>
			<tr><td>Little Endian (Hex)</td><td><?php echo $result;?></td></tr>
		</table>
	</div>
<?php
}
?>
<form action='' method='post'>
	<div class="form-group">
		<label for="input">Input:</label>
		<input class="form-control" type='text' name='input' id='input' value='<?php echo $_POST['input']?>'>
	</div>
	
	<div class="form-group">
		<label>Input Encoding:</label>
		
		<div class="form-check">
		  <label class="form-check-label">
			<input type="radio" class="form-check-input" name="encoding" value="hex"<?php echo $_POST['encoding']=='hex' ? ' checked': ''?>>Hex
		  </label>
		</div>
		
		<div class="form-check">
		  <label class="form-check-label">
			<input type="radio" class="form-check-input" name="encoding" value="integer"<?php echo $_POST['encoding']=='integer' ? ' checked': ''?>>Integer
		  </label>
		</div>
		
	</div>

	<input type='submit' class="btn btn-success btn-block"/>
</form>
<?php 
include_once("html_iframe_footer.php");		








Tutorials
About Us
Contents have been open source in GITHUB. Please give me a ⭐ if you found this helpful :)
Community
Problem? Raise me a new issue.
Support Us
Buy me a coffee. so i can spend more nights for this :)

BTCSCHOOLS would like to present you with more pratical but little theory throughout our tutorials. Pages' content are constantly keep reviewed to avoid mistakes, but we cannot warrant correctness of all contents. While using this site, you agree to accept our terms of use, cookie & privacy policy. Copyright 2019 by BTCSCHOOLS. All Rights Reserved.