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

Urgent! - Working with bits/bytes in C

P: 5
Hi all,

I am new in this community but already need support as below:
Hope you guys could help!

The idea was: The user input some text in the program and then I put the information inserted in a char vector.


int c;
char s[];
while(--lim>0 && (c=getchar()) !=EOF && c!='\n')
s[i++]=c;


So , until now, I was using a char vector (8 bits or 1 byte) in my project ...the problem is that now I need to input a single bit "1" in the middle of the vector. (fyi - it is a hash function alg.)

I was wondering to use a bit vector instead of a char vector ... how I do that in C?... Any suggestions on how to do that? ... Feel free to propose any other work around!

Thanks for your attention and support :)
Gus
Dec 28 '06 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,510
in C you can use bitfeilds or bitwise operators (to set/reset bits) and in C++ vector<bool> or the bitset class

have a look the discussion
http://en.wikipedia.org/wiki/Bit_array#Language_support
http://nkari.uw.hu/Tutorials/CPPTips/bitset_v_vec_bool
Dec 28 '06 #2

P: 1
Hi all,

I am new in this community but already need support as below:
Hope you guys could help!

The idea was: The user input some text in the program and then I put the information inserted in a char vector.


int c;
char s[];
while(--lim>0 && (c=getchar()) !=EOF && c!='\n')
s[i++]=c;


So , until now, I was using a char vector (8 bits or 1 byte) in my project ...the problem is that now I need to input a single bit "1" in the middle of the vector. (fyi - it is a hash function alg.)

I was wondering to use a bit vector instead of a char vector ... how I do that in C?... Any suggestions on how to do that? ... Feel free to propose any other work around!

Thanks for your attention and support :)
Gus


HI ...
To solve ur problem,there is a technique in C. That is using bitfields.Using bit field we can assign directly to any partcular bit.For this U can refer balguruswamy's book with title ANSI C.
I hope this will solve ur question
Dec 29 '06 #3

Post your reply

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