Les dejo el código fuente de cada archivo.
Saludos!.
byte.h
Código PHP:
#define __NIBBLEBITS__ 4
#define __BYTEBITS__ 8
typedef struct e_byte
{
int value;
int highestNibble;
int lowestNibble;
}BYTE;
BYTE getByte ( int value );
static int getHighestNibble ( int value );
static int getLowestNibble ( int value );
Código PHP:
#include "byte.h"
BYTE getByte ( int value )
{
BYTE byte;
byte.value = value;
byte.highestNibble = getHighestNibble ( value );
byte.lowestNibble = getLowestNibble ( value );
return byte;
}
static int getHighestNibble ( int value )
{
return value >> __NIBBLEBITS__;
}
static int getLowestNibble ( int value )
{
int highestNibble;
highestNibble = getHighestNibble ( value );
highestNibble <<= __NIBBLEBITS__;
return value ^ highestNibble;
}
Código PHP:
#include "byte.h"
#define __MAXSIZE__ 8
void push ( BYTE byte );
BYTE pop ( void );
BYTE get ( int i );
int bytesCount ( void );
Código PHP:
#include "bytearray.h"
static BYTE bytes [ __MAXSIZE__ ];
static int index = 0;
void push ( BYTE newbyte )
{
bytes [ index ] = newbyte;
index += 1;
}
BYTE pop ( void )
{
return bytes [ --index ];
}
BYTE get ( int i )
{
int k;
for ( k = 0 ; k < index ; k++ )
{
if ( k == i )
{
return bytes [ i ];
}
}
}
int bytesCount ( void )
{
return index++;
}
Código PHP:
#include "bytearray.h"
typedef unsigned long BITDATATYPE;
void getBytes ( BITDATATYPE value );
static void rightShift ( int *value , int shift );
Código PHP:
#include "converter.h"
void getBytes ( BITDATATYPE value )
{
BITDATATYPE tmpvalue;
int leftshifts;
tmpvalue = value;
leftshifts = 0;
while ( value != 0 )
{
while ( ( ( tmpvalue >> __BYTEBITS__ ) << __BYTEBITS__ ) != 0 )
{
tmpvalue >>= __BYTEBITS__;
leftshifts += 1;
}
push ( getByte ( tmpvalue ) );
rightShift ( (int*)&tmpvalue , leftshifts );
value = ( value ^ ( tmpvalue ) ) << __BYTEBITS__;
tmpvalue = value;
leftshifts = 0;
}
}
static void rightShift ( int *value, int shift )
{
int i;
for ( i = 1 ; i <= shift ; i++ )
{
*value <<= __BYTEBITS__;
}
}