[Tinyos-help] Access and set individual bit in payload

Mindaugas Jaraminas minde.j at gmail.com
Fri Jan 30 05:11:33 PST 2009


Hi Ittipong

Here is quick example:

#include <stdio.h>
#include <string.h>
#define UINT8 unsigned char

void display(UINT8 * buffer, UINT8 Length){
	UINT8 * tmp = buffer;
	UINT8 mask;
	int i, y;
	for (i = 0; i < Length; i++) {
		mask = 1;
		printf ("Printing byte 0x%02X,  bits = ", *tmp);
		for (y=0; y < 8; y++ ){
			printf ("%X,", (*tmp & mask) >> y);
			mask = mask << 1;
		}
		printf ("\n");
		tmp ++;
	}
}

int main ()
{
  UINT8 buff[3]= {0x01, 0xAA, 0x03,};
  UINT8 len = sizeof(buff);

  display(buff, len);

  return 0;
}

The output is:

Printing byte 0x01,  bits = 1,0,0,0,0,0,0,0,
Printing byte 0xAA,  bits = 0,1,0,1,0,1,0,1,
Printing byte 0x03,  bits = 1,1,0,0,0,0,0,0,

-- 
Best regards
Mindaugas Jaraminas

George Carlin  - "May the forces of evil become confused on the way to
your house."


2009/1/30 Ittipong Khemapech <ik.tinyos at googlemail.com>:
> Hi,
>
> Is it possible to access and set value to each individual bit of message_t
> payload? I've been through the archives and found nothing. If you have done
> before, please share or give me some hints.
>
> Many thanks in advance,
> Ittipong
>
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>


More information about the Tinyos-help mailing list