PDA

Click to See Complete Forum and Search --> : Macros...humm


Azz00
Dec 7th, 2002, 08:56 PM
I have this macros....
is there anyway i can make another one to convert the madePkt Back to the 2 ascii chars that made it up ?

typedef unsigned short p_type;

/*Make a Packet ID from 2 ASCII Chars */
#define make_pkt(a,b) p_type(((a)&255) | (b)<<8)

#define madePkt make_pkt ('C','H')

kedaman
Dec 8th, 2002, 02:45 AM
#define a(x) ((a)&0xFF)
#define b(x) ((b)>>8)

Azz00
Dec 8th, 2002, 07:25 AM
Hmmm....Lookies:

#include "stdafx.h"

typedef unsigned short p_type;

/*Make a Packet ID from 2 ASCII Chars */
#define make_pkt(a,b) p_type(((a)&255) | (b)<<8)
#define madePkt make_pkt ('C','H')


int main( void )
{

printf("madePkt: %d\n", madePkt );

return 0;
}

Output "madePkt: 18499"

Basically i want to get back the 2 ASCII Chars from the outputting number which i dont think is possible without having a loop to go through the whole ASCII Char set and compare results ?

CornedBee
Dec 8th, 2002, 01:29 PM
keda's macros work, no loops needed...