<?php // example 01 : simple open and close
require_once( "cfile.class.php" );
echo "<b>EXAMPLE 11</b>: using static functions<br><br>" ;
echo "<b STYLE=\"font-size:16pt;color:#598CCE;\">BYTE REVERSION</b><br>" ;
$INPUT_DATA = "this is a long text which I am used to write here down for tests" ;
echo "input (a string) : <b>$INPUT_DATA</b><br>" ;
echo "reversing byte order ...<br>" ;
echo "output : <b>".strtoupper( cfile::reverse_byte_order( $INPUT_DATA, 1, false ) )."</b><br><br>" ;
$INPUT_DATA = "12" ;
echo "input (a string including numbers only) : <b>$INPUT_DATA</b><br>" ;
echo "reversing byte order ...<br>" ;
echo "output : <b>".strtoupper( cfile::reverse_byte_order( $INPUT_DATA, 1, false ) )."</b><br><br>" ;
$INPUT_DATA = 140 ;
echo "input (an integer) : <b>$INPUT_DATA</b><br>" ;
echo "reversing byte order ...<br>" ;
echo "output : <b>".strtoupper( cfile::reverse_byte_order( $INPUT_DATA, 1, false ) )."</b><br><br>" ;
$INPUT_DATA = 3.14 ;
echo "input (a floating value) : <b>$INPUT_DATA</b><br>" ;
echo "reversing byte order ...<br>" ;
echo "output : <b>".strtoupper( cfile::reverse_byte_order( $INPUT_DATA, 1, false ) )."</b><br><br>" ;
echo "<br><b STYLE=\"font-size:16pt;color:#598CCE;\">SWAP BYTE NIBBLES</b><br>" ;
$INPUT_DATA = 140 ;
echo "input (an integer) : <b>$INPUT_DATA</b><br>" ;
echo "swapping nibbles ...<br>" ;
echo "output : <b>".strtoupper( cfile::swap_nibble( $INPUT_DATA ) )."</b><br><br>" ;
echo "<br><b STYLE=\"font-size:16pt;color:#598CCE;\">GET N-BYTES FOR AN INTEGER</b><br>" ;
$INPUT_DATA = 0 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
$INPUT_DATA = 15 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
$INPUT_DATA = 255 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
$INPUT_DATA = 256 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".strtoupper( cfile::get_nbytes( $INPUT_DATA, $nbits ) )."</b><br>" ;
echo "bits : <b>$nbits</b><br><br>" ;
$INPUT_DATA = 4096 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
$INPUT_DATA = 65535 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
$INPUT_DATA = 65536 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".strtoupper( cfile::get_nbytes( $INPUT_DATA, $nbits ) )."</b><br>" ;
echo "bits : <b>$nbits</b><br><br>" ;
$INPUT_DATA = pow( 2, 8 * 4 ) - 1 ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
$INPUT_DATA = pow( 2, 8 * 4 ) ;
echo "input : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>".cfile::get_nbytes( $INPUT_DATA )."</b><br><br>" ;
echo "<br><b STYLE=\"font-size:16pt;color:#598CCE;\">FLOAT TO HEX</b><br>" ;
$INPUT_DATA = 12.2 ;
echo "input (an integer) : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>0x".strtoupper( cfile::float_to_hex( $INPUT_DATA ) )."</b><br>" ;
echo "back to input : <b>".round( cfile::hex_to_float( cfile::float_to_hex( $INPUT_DATA ) ), 2 )."</b><br><br>" ;
echo "<br><b STYLE=\"font-size:16pt;color:#598CCE;\">DOUBLE TO HEX</b><br>" ;
$INPUT_DATA = 12.2 ;
echo "input (an integer) : <b>$INPUT_DATA</b><br>" ;
echo "output : <b>0x".strtoupper( cfile::double_to_hex( $INPUT_DATA ) )."</b><br>" ;
echo "back to input : <b>".round( cfile::hex_to_double( cfile::double_to_hex( $INPUT_DATA ) ), 2 )."</b><br><br>" ;
$INPUT = 258 ;
echo "dechex : $INPUT > 0x".dechex( $INPUT )."<br>" ;
$R = unpack( "h*", pack( "i*", $INPUT ) ) ;
echo "dechex : $INPUT > 0x".$R[1]."<br>" ;
?>
|