JustKernel

Ray Of Hope

bitwise operations

Assignment to 4 bit

#include <stdio.h>

typedef unsigned char uint8;

struct nib

{

uint8 an_term_tp:4,

cn_term_tp:4;

};

void main()

{

int an_term = 1;

int cn_term = 2;

uint8 ch;

struct nib nib_obj;

ch = *(char *)(int *)&an_term;

printf(“%d\n “, ch);

if (ch == 1)

printf(“\n little endian”);

nib_obj.an_term_tp = (char)(an_term) & 0x0f;

nib_obj.cn_term_tp = (char)(cn_term) & 0x0f;

printf(“an term = %d and cn_term = %d\n”, nib_obj.an_term_tp, nib_obj.cn_term_tp); }

Answer 1 &  2

Originally Posted On:2010-05-06 04:34:44

Anshul Makkar, anshul_makkar@justkernel.com

Tags:


Leave a Reply

Your email address will not be published. Required fields are marked *