hi All,

I want to fit "10"(Integer) in format like

000001 00 i.e. first number in six bits and second in two bits

so that finally i read it as 04 in Integer

could anyone suggest how can i do this ?

I am trying with

struct number
{
UINT a : 6;
UINT b : 2;
}

number obj;

obj.a = 1;
obj.b = 0;

but i don't know how to proceed with...

please suggest the solution..

Thanks & Regards
Mukesh:)

the ordering of data declared as bit fields is implementation dependant. you have to test and figure out what it is for your compiler.

#include <iostream>

int main()
{
  // assumes that the ordering of data declared as bit fields is from
  // low to high bit. this is implementation dependant
  struct number { unsigned second:2 ; unsigned first:6 ; };
  union { number n ; unsigned char c ; };
  n.first = 1 ; n.second = 0 ;
  std::cout << int(c) << '\n' ;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.