C programming help

cHeeZeFacTory

Golden Member
Apr 23, 2001
1,658
0
0
Hi

I need some quick C programming help.

I need to write a function processes a 8 byte hex message.

How do I break up the hex message in an array of size 8 ? so i can access each byte individually?
 

cHeeZeFacTory

Golden Member
Apr 23, 2001
1,658
0
0
unsigned int hex = 0x123456787; // 4 bytes
unsigned char arr[4]; // array of 4 bytes
int index = 0;

for( index; index<4; index++ )
{
// shift the hex number over by a byte and store the least significant byte in arr
// NOTE: the value of hex remains the same, we are just shifting it an extra byte each time
arr[index] = (hex >> index*8) & 0x00ff;
}

what is &gt and &amp doing?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
&gt = >

&amp = &

the >> is the bitshift operator
and & is the bitwise & operator

The attach code function in FuseTalk is broken atm...and has been for awhile so it parses out those signs into their html values instead of leaving them be :(