By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,925 Members | 1,134 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,925 IT Pros & Developers. It's quick & easy.

Reading bit vectors vertically

P: 3
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
Mar 24 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 1,510
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
Mar 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.