Foros del Web » Programación para mayores de 30 ;) » C/C++ »

Sugerencias para este código

Estas en el tema de Sugerencias para este código en el foro de C/C++ en Foros del Web. Hola a todos. Estoy trabajando con C. Hice un código para poder obtener cada byte de cualquier valor pasado como argumento a la función principal ...
  #1 (permalink)  
Antiguo 28/11/2007, 00:58
 
Fecha de Ingreso: marzo-2005
Mensajes: 1.418
Antigüedad: 19 años, 1 mes
Puntos: 9
Sugerencias para este código

Hola a todos. Estoy trabajando con C. Hice un código para poder obtener cada byte de cualquier valor pasado como argumento a la función principal del código, y de estos obtener cada nibble. Me gustaría saber que se puede mejorar, que cosas tendría que tener en cuenta que no tuve, etc. Si alguien es tan amable de ponerse a leer el código detenidamente y probarlo, le estaré muy agradecido. No tengo ningún apuro!.
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 ); 
byte.c
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;            

bytearray.h
Código PHP:
#include "byte.h"
#define __MAXSIZE__         8

void push BYTE byte );
BYTE pop void ); 
BYTE get int i );
int bytesCount void ); 
bytearray.c
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 ( 
index k++ )
    {
        if ( 
== )
        {
            return 
bytes ];
        }
    }  
}

int bytesCount void )
{
    return 
index++;

converter.h
Código PHP:
#include "bytearray.h"

typedef unsigned long BITDATATYPE;

void getBytes BITDATATYPE value );
static 
void rightShift int *value int shift ); 
converter.c
Código PHP:
#include "converter.h"

void getBytes BITDATATYPE value )
{
    
    
BITDATATYPE tmpvalue;
    
int leftshifts;
    
    
tmpvalue value;
    
leftshifts 0;
    
    while ( 
value != )
    {                
        while ( ( ( 
tmpvalue >> __BYTEBITS__ ) << __BYTEBITS__ ) != )
        {
            
tmpvalue >>= __BYTEBITS__;
            
leftshifts += 1;
        } 
        
push getByte tmpvalue ) );
        
rightShift ( (int*)&tmpvalue leftshifts );              
        
value = ( value ^ ( tmpvalue ) ) << __BYTEBITS__;
        
tmpvalue value;
        
leftshifts 0;         
    }    
}

static 
void rightShift int *valueint shift )
{
    
int i;
    
    for ( 
<= shift i++ )
    {
        *
value <<= __BYTEBITS__;
    }

__________________
Add, never Remove
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:25.