Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading bit vectors vertically

Newbie
 
Join Date: Mar 2007
Posts: 3
#1: Mar 24 '07
I am writing a logic simulator for boolean circuits. I have a textfile which will contain vectors like this

abc
001
100
111
...

I want to be able to bit pack these vectors to get a = 110, b = 100, c = 101 so that i can simulate them using a 32 bit int or a 64 bit set (hence 32/64 vectors at a time). I'm trying to figure out the most efficient way to quickly read in and bitpack these vectors.

One possible ways to do this is to read the strings in order. and then reverse them to get
111
100
001
and then transpose this matrix to get
110
100
101

but i'm wondering if there would be any other efficient way in C++ to accomplish this? maybe there exist some C++ libraries to read text files containing strings of 0/1 and manipulate them?

thanks

Expert
 
Join Date: Nov 2006
Location: UK
Posts: 1,320
#2: Mar 24 '07

re: Reading bit vectors vertically


initially the simplest way is to read the data into a 2D array of vector, e.g. to hold 100 lines of data
Expand|Select|Wrap|Line Numbers
  1. int bits[100][3]
  2.  
you an then reverse transpose the array as you wish.
When it is working you can look at efficency- you are only using one bit of a 32-bit integer. For example, you could use char which is a byte sized integer or bit fields or bitwise operators to store 8 bits in a byte etc
Reply