Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Bit Manipulation

Reply
Thread Tools

Bit Manipulation

 
 
Al
Guest
Posts: n/a
 
      03-06-2007
HI,
I'm an hardware designer that HAS to define the software structure for
accessing "my" hardware, so please be patient with me.

Let me put my problem first:
I have "a lot" of "hardware" variables that are non-standard size
(like one, two, seven and so on - bits). What is the best way to work
with them? They MUST be "composed" into 32-bit words before writing
them into the hardware.

Now let me go a little bit more specific:
My first hint was to use a structure of bit-field, but I have some
questions that could not find an answer:
1- Due to portability issues I CANNOT assume that a "group" of bit-
fields summing 32-bits is stored in and int (unsigned)? (I'm correct?)
2- Bit-fields can be viewed as a sub-set of int (?). What if my bit-
field has more bits than the processor defined int? (Example: a bit-
field with 40-bits in a 32-bit machine?) What happens in this
situation?
3- For grouping a set of bit-fields into and unsigned int can I still
use bit-shifting?
4- What happens if I try something like i=255 and I has only 4 bits?
5- The alternatives for bit-field are using simple unsigned int and
perform bit manipulation, but that complicates programming? (Do you
agree?) (Note that 32-bit composing is limited to communication
functions.)


If you have other suggestions that you would like to share I would
appreciate it Very Much.

Thank you for your attention and patience.

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      03-06-2007

Al wrote:
> HI,
> I'm an hardware designer that HAS to define the software structure for
> accessing "my" hardware, so please be patient with me.


<snip>

Please try comp.arch

 
Reply With Quote
 
 
 
 
Jason Curl
Guest
Posts: n/a
 
      03-06-2007
Al wrote:
> HI,
> I'm an hardware designer that HAS to define the software structure for
> accessing "my" hardware, so please be patient with me.
>
> Let me put my problem first:
> I have "a lot" of "hardware" variables that are non-standard size
> (like one, two, seven and so on - bits). What is the best way to work
> with them? They MUST be "composed" into 32-bit words before writing
> them into the hardware.
>
> Now let me go a little bit more specific:
> My first hint was to use a structure of bit-field, but I have some
> questions that could not find an answer:
> 1- Due to portability issues I CANNOT assume that a "group" of bit-
> fields summing 32-bits is stored in and int (unsigned)? (I'm correct?)
> 2- Bit-fields can be viewed as a sub-set of int (?). What if my bit-
> field has more bits than the processor defined int? (Example: a bit-
> field with 40-bits in a 32-bit machine?) What happens in this
> situation?
> 3- For grouping a set of bit-fields into and unsigned int can I still
> use bit-shifting?
> 4- What happens if I try something like i=255 and I has only 4 bits?
> 5- The alternatives for bit-field are using simple unsigned int and
> perform bit manipulation, but that complicates programming? (Do you
> agree?) (Note that 32-bit composing is limited to communication
> functions.)
>
>
> If you have other suggestions that you would like to share I would
> appreciate it Very Much.


You also have to be careful, that if you're using C, the ordering of the
bitfields is implementation defined. We had this problem that by
changing compilers we had to redefine all our structures to keep the
same bit representation.

Why not define an unsigned int (or if using Posix a uint32_t defined by
<inttypes.h>) and define macros to set and clear bits? To keep
portability if you need it (but there'll be a performance cost) don't
use bitfields in a structure but define an API/wrapper that will take a
portable structure and convert it to the bit field you want just before
you write directly to the hardware?

>
> Thank you for your attention and patience.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Reversing Bit Order.. i.e. MSB becomes bit 0, LSB becomes bit 15 benn686@hotmail.com C++ 9 08-22-2007 12:13 AM
"LoadLibrary" of a 32 bit so with 64 bit java on a 64 bit machine markryde@gmail.com Java 3 01-19-2007 10:30 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments