473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

bit vector

HI.first of all i am sorry on my very bad english(spelling and grammar)
I have one problem.. need to write program that simulates Eratostens
riddle(in C) using bit vector, but I dont know how to implement bit
vector
and how to use it.

I've got something like this:

#define BIT_SET(v, n) (v[(n)>>3] |= 1U << ((n) & 7))
#define BIT_CLR(v, n) (v[(n)>>3] &= ~(1U << ((n) & 7)))
#define BIT_ISSET(v, n) (v[(n)>>3] & (1U << ((n) & 7)))

but I dont understand this, so if you can help me i would appreciate
that..

THANK YOU...

Nov 14 '05 #1
21 7158


si*****@inet.hr wrote:
HI.first of all i am sorry on my very bad english(spelling and grammar)
I have one problem.. need to write program that simulates Eratostens
riddle(in C) using bit vector, but I dont know how to implement bit
vector
and how to use it.

I've got something like this:

#define BIT_SET(v, n) (v[(n)>>3] |= 1U << ((n) & 7))
#define BIT_CLR(v, n) (v[(n)>>3] &= ~(1U << ((n) & 7)))
#define BIT_ISSET(v, n) (v[(n)>>3] & (1U << ((n) & 7)))

but I dont understand this, so if you can help me i would appreciate
that..


As this is obviously a homework question, I just will recap some ideas:

We have an array
unsigned char v[MAXNUMBER];
We mark every number i from 2..MAXNUMBER-1 as potential prime number
by setting v[i] to 1, then apply the sieve method to get rid of
non-prime numbers. In the end, we know all prime numbers in the above
range as only they will still have a 1 entry in v.

As the number of bits per byte (CHAR_BIT) is at least 8, we think
"Hey, if we store the information bitwise, we can save factor 8
and can get up to 8*MAXNUMBER-1 with the same array".
Now, we want to save the information for j*8+0..j*8+7 in v[j] and
retrieve it from there. This is where the above macros come in.
You could alternatively write them as
#define BIT_SET(v, n) (v[(n)/8] |= 1U << ((n)%8))
#define BIT_CLR(v, n) (v[(n)/8] &= ~(1U << ((n)%8)))
#define BIT_ISSET(v, n) (v[(n)/8] & (1U << ((n)%8)))
where BIT_SET sets for n=8*j+k the k'th bit of v[j]
(i.e. the overall n'th bit) to 1, BIT_CLR sets it to 1
and BIT_ISSET gives you 0 if the bit is not set and non-zero
if it is set.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2
yes it is my homework (I am student), and sorry if I bothering you
but i dont have much chioce....

Nov 14 '05 #3
On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:
yes it is my homework (I am student), and sorry if I bothering you
but i dont have much chioce....


Yes you do have a choice, you can ask your tutor. It's their job to
explain if you didn't understand in the class (you did go to the class,
right?). And the purpose of homework is to see whether the student has
understood, not to see whether they can get someone else to do it for
them. You've already been given an explanation here of what the macros
are for and how to go avout solving the problem...

Chris C
Nov 14 '05 #4
Chris Croughton <ch***@keristor.net> writes:
On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:
yes it is my homework (I am student), and sorry if I bothering you
but i dont have much chioce....


Yes you do have a choice, you can ask your tutor.


It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.
--
"Give me a couple of years and a large research grant,
and I'll give you a receipt." --Richard Heathfield
Nov 14 '05 #5
In article <11*********************@z14g2000cwz.googlegroups. com>,
si*****@inet.hr says...
yes it is my homework (I am student), and sorry if I bothering you
but i dont have much chioce....


Here's a hint. Take each one of the macros, and write some simple
test code to take a known value (bit pattern if you like) and
see what they do. Print out the contents of them before and
after the BET_SET and BIT_CLR operations. Once you see it with
your own eyes it should make more sense. That's going to do
you a lot more good in the long run than somebody just telling
you what to do.
--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #6
I cant understand everything what my tutor say, because he explain
that on quite abstract and ambiguous way, and I am just beginer in
programming(I am 23 old, I started to programming before 2 years(I got
pc before 4)) so the easiest way is to ask on the news group...here
... and hope that somebody will answer may question....
by the way I am from Croatia..not US....and there is not many books on
internet writen on croatian language .. (you can see how my english
is bad)...

anyway thanks to everyone

Nov 14 '05 #7
In article <11*********************@o13g2000cwo.googlegroups. com>,
si*****@inet.hr says...
I cant understand everything what my tutor say,
At least you have fun. Not everyone does.
because he explain that on quite abstract and ambiguous way,


So ask him to provide a concrete example, on paper, showing every
step the next time you have a problem understanding him.

If he refuses, you have the wrong tutor.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #8
In article <MP************************@news.verizon.net>,
ra*********@FOOverizonBAR.net says...
In article <11*********************@o13g2000cwo.googlegroups. com>,
si*****@inet.hr says...
I cant understand everything what my tutor say,


At least you have fun. Not everyone does.


"fun" should be "one".

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #9
Randy Howard wrote:

In article <MP************************@news.verizon.net>,
ra*********@FOOverizonBAR.net says...
In article <11*********************@o13g2000cwo.googlegroups. com>,
si*****@inet.hr says...
I cant understand everything what my tutor say,


At least you have fun. Not everyone does.


"fun" should be "one".


It's more fun with two.
Nov 14 '05 #10
In article <11*********************@o13g2000cwo.googlegroups. com>,
si*****@inet.hr says...
I cant understand everything what my tutor say,
At least you have fun. Not everyone does.
because he explain that on quite abstract and ambiguous way,


So ask him to provide a concrete example, on paper, showing every
step the next time you have a problem understanding him.

If he refuses, you have the wrong tutor.

--
Randy Howard (2reply remove FOOBAR)
"Making it hard to do stupid things often makes it hard
to do smart ones too." -- Andrew Koenig
Nov 14 '05 #11
....he is very strange guy...

Nov 14 '05 #12
On Tue, 15 Feb 2005 13:18:22 -0800, in comp.lang.c , Ben Pfaff
<bl*@cs.stanford.edu> wrote:
Chris Croughton <ch***@keristor.net> writes:
On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:
yes it is my homework (I am student), and sorry if I bothering you
but i dont have much chioce....


Yes you do have a choice, you can ask your tutor.


In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.


As far as anyone in the UK and probably Europe is concerned, the three are
synonyms.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #13
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
Chris Croughton <ch***@keristor.net> writes:
On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:
yes it is my homework (I am student), and sorry if I bothering you
but i dont have much chioce....


Yes you do have a choice, you can ask your tutor.


It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.


Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is teaching
you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).

Chris C
Nov 14 '05 #14

Chris Croughton wrote:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
Chris Croughton <ch***@keristor.net> writes:
On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:

yes it is my homework (I am student), and sorry if I bothering you but i dont have much chioce....

Yes you do have a choice, you can ask your tutor.
It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.


Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is

teaching you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).

Chris C

He give us short explaination, but almost nobody understand what he
says...

Nov 14 '05 #15
Chris Croughton <ch***@keristor.net> writes:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.


Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is teaching
you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).


So a "tutor" who fits in that category? In the US it would be
someone you hired on the side to help you better understand the
course material. Thus the confusion.
--
"Give me a couple of years and a large research grant,
and I'll give you a receipt." --Richard Heathfield
Nov 14 '05 #16
si*****@inet.hr wrote:
Chris Croughton wrote:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
<snip>
In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.

<snip>
He give us short explaination, but almost nobody understand what he
says...


Then you should go on mass to him and tell him that his explanation is
not good enough.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #17
On 16 Feb 2005 06:34:39 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:
Chris Croughton wrote:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
> Chris Croughton <ch***@keristor.net> writes:
>
>> On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
>> <si*****@inet.hr> wrote:
>>
>>> yes it is my homework (I am student), and sorry if I bothering
>>> you
>>> but i dont have much chioce....
>>
>> Yes you do have a choice, you can ask your tutor.
>
> It's a big assumption that a student has a tutor. That's (as I
> understand it) part of the British system of education, but not
> part of the US system.
>
> In the US, I'd tell the student to ask the course instructor or a
> teaching assistant for help.


Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is
teaching
you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).

He give us short explaination, but almost nobody understand what he
says...


In which case you (all of you who don't understand) need to ask him for
a full explanation. If he still doesn't explain properly complain to
the head of the department, his superior or to whoever is in charge of
teaching. He is presumably being employed to teach, if no one is
understanding him then something needs to be done.

Letting him get away with bad teaching does not solve the problem.

Chris C
Nov 14 '05 #18

Chris Croughton wrote:
On 16 Feb 2005 06:34:39 -0800, si*****@inet.hr
<si*****@inet.hr> wrote:
Chris Croughton wrote:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:

> Chris Croughton <ch***@keristor.net> writes:
>
>> On 15 Feb 2005 11:48:23 -0800, si*****@inet.hr
>> <si*****@inet.hr> wrote:
>>
>>> yes it is my homework (I am student), and sorry if I bothering >>> you
>>> but i dont have much chioce....
>>
>> Yes you do have a choice, you can ask your tutor.
>
> It's a big assumption that a student has a tutor. That's (as I
> understand it) part of the British system of education, but not
> part of the US system.
>
> In the US, I'd tell the student to ask the course instructor or a > teaching assistant for help.

Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is
teaching
you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).
He give us short explaination, but almost nobody understand what he
says...


In which case you (all of you who don't understand) need to ask him

for a full explanation. If he still doesn't explain properly complain to
the head of the department, his superior or to whoever is in charge of teaching. He is presumably being employed to teach, if no one is
understanding him then something needs to be done.

Letting him get away with bad teaching does not solve the problem.

Chris C


first :somethings he explain well,and other not so well
sec: he will leave very soon, so nobody really care

Nov 14 '05 #19

Ben Pfaff wrote:
Chris Croughton <ch***@keristor.net> writes:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.


Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is teaching you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).


So a "tutor" who fits in that category? In the US it would be
someone you hired on the side to help you better understand the
course material. Thus the confusion.
--
"Give me a couple of years and a large research grant,
and I'll give you a receipt." --Richard Heathfield


I am from Croatia - here is everthing wrong( upside down)

Nov 14 '05 #20
On Wed, 16 Feb 2005 08:57:31 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
Chris Croughton <ch***@keristor.net> writes:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.


Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is teaching
you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).


So a "tutor" who fits in that category? In the US it would be
someone you hired on the side to help you better understand the
course material. Thus the confusion.


Here (UK) a tutor could be privately hired, or could be a person
appointed to oversee the studies of a group of students (a university
tutor often does that, and may also be concerned with the wellbeing of
the students in other ways), or in general is anyone who teaches (in
particular, a person who teaches a specific subject).

The usage has changed over time, and in different social classes (rich
people 50 or so years ago often were taught at home by tutors hired by
the parents, I suspect that the US usage has kept that sort of meaning),
whereas at some schools all of the teachers are known as 'tutors'.

Chris C
Nov 14 '05 #21
On Wed, 16 Feb 2005 21:23:56 +0000, Chris Croughton
<ch***@keristor.net> wrote:
On Wed, 16 Feb 2005 08:57:31 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:
Chris Croughton <ch***@keristor.net> writes:
On Tue, 15 Feb 2005 13:18:22 -0800, Ben Pfaff
<bl*@cs.stanford.edu> wrote:

It's a big assumption that a student has a tutor. That's (as I
understand it) part of the British system of education, but not
part of the US system.

In the US, I'd tell the student to ask the course instructor or a
teaching assistant for help.

Whether you call them a 'tutor', 'course instructor', 'Lehrer' or
whatever is not relevant, I'm referring to "the person who is teaching
you and who gave you the homework". That applies even to remote
schooling (learning by mail / email / TV / etc.).
So a "tutor" who fits in that category? In the US it would be
someone you hired on the side to help you better understand the
course material. Thus the confusion.


Here (UK) a tutor could be privately hired, or could be a person
appointed to oversee the studies of a group of students (a university
tutor often does that, and may also be concerned with the wellbeing of
the students in other ways), or in general is anyone who teaches (in
particular, a person who teaches a specific subject).

The usage has changed over time, and in different social classes (rich
people 50 or so years ago often were taught at home by tutors hired by
the parents, I suspect that the US usage has kept that sort of meaning),


In my experience, it's usually clarified by saying "private tutor."
whereas at some schools all of the teachers are known as 'tutors'.

Chris C


--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
10
by: Bob | last post by:
Here's what I have: void miniVector<T>::insertOrder(miniVector<T>& v,const T& item) { int i, j; T target; vSize += 1; T newVector; newVector=new T;
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
16
by: Martin Jørgensen | last post by:
Hi, I get this using g++: main.cpp:9: error: new types may not be defined in a return type main.cpp:9: note: (perhaps a semicolon is missing after the definition of 'vector') main.cpp:9:...
23
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: ...
6
by: zl2k | last post by:
hi, there I am using a big, sparse binary array (size of 256^3). The size may be changed in run time. I first thought about using the bitset but found its size is unchangeable. If I use the...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.