473,763 Members | 3,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About very long Bit-numbers (bitfields?)

Hi

I don't know if I am using right words (bit-number), but this is what I
mean:

You can set a 64 bit number:

unsigned long a;

Now you can use binary operators to manipulate variable a (for example
a |= (unsigned long) 128
).

How about if I want to get for example a 640 bit long *one* number (say b)
and do the same binary operations to it (b |= 128)? I haven't found answer
for this ... do I need to use Bitfields:

struct BITS
{
unsigned long b1;
unsigned long b2;
unsigned long b3;
.... (10 times)
};

I don't know ...
Jul 22 '05 #1
18 2370
Juha Kettunen <no*@valid.co m> spoke thus:
How about if I want to get for example a 640 bit long *one* number (say b)
and do the same binary operations to it (b |= 128)? I haven't found answer
for this ... do I need to use Bitfields:


You might look at vector<bool>, although I have no idea how useful
you'll find it.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #2
Juha Kettunen <no*@valid.co m> spoke thus:
How about if I want to get for example a 640 bit long *one* number (say b)
and do the same binary operations to it (b |= 128)? I haven't found answer
for this ... do I need to use Bitfields:


You might look at vector<bool>, although I have no idea how useful
you'll find it.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #3
On Fri, 9 Apr 2004 10:33:24 +0100, "Juha Kettunen" <no*@valid.co m> wrote:
Hi

I don't know if I am using right words (bit-number), but this is what I
mean:

You can set a 64 bit number:

unsigned long a;
Just FYI, the number of bits in a long (unsigned or otherwise) is
platform-dependent. On my system they're only 32 bits. But that doesn't
have much bearing on your real question, which is how to get /real/ long
bit sequences.
How about if I want to get for example a 640 bit long *one* number (say b)
and do the same binary operations to it (b |= 128)? I haven't found answer
for this ... do I need to use Bitfields:


For that, Christopher's suggestion of vector<bool> may be adequate.
vector<bool> is the "black sheep" of the STL container family...becaus e it
doesn't meet all the usual vector requirements:

#include <vector>

int main()
{
std::vector<cha r> vc;
std::vector<boo l> vb;

vc.push_back('x ');
vc.push_back('y ');
vb.push_back(tr ue);
vb.push_back(tr ue);

std::vector<cha r>::iterator vcit = vc.begin();
std::vector<boo l>::iterator vbit = vb.begin();

*vcit = 'z'; // OK
*vbit = false; // OK

char *cp = &vc[0]; // OK
bool *bp = &vb[0]; // Oops: won't compile.

return 0;
}

On the other hand, it provides some operation specialized for bits that
std::vector<som ething-other-than-bool> does not. Josuttis 6.2.6 has the
gory details. If you can avoid the potholes, it may work fine for you.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #4
On Fri, 9 Apr 2004 10:33:24 +0100, "Juha Kettunen" <no*@valid.co m> wrote:
Hi

I don't know if I am using right words (bit-number), but this is what I
mean:

You can set a 64 bit number:

unsigned long a;
Just FYI, the number of bits in a long (unsigned or otherwise) is
platform-dependent. On my system they're only 32 bits. But that doesn't
have much bearing on your real question, which is how to get /real/ long
bit sequences.
How about if I want to get for example a 640 bit long *one* number (say b)
and do the same binary operations to it (b |= 128)? I haven't found answer
for this ... do I need to use Bitfields:


For that, Christopher's suggestion of vector<bool> may be adequate.
vector<bool> is the "black sheep" of the STL container family...becaus e it
doesn't meet all the usual vector requirements:

#include <vector>

int main()
{
std::vector<cha r> vc;
std::vector<boo l> vb;

vc.push_back('x ');
vc.push_back('y ');
vb.push_back(tr ue);
vb.push_back(tr ue);

std::vector<cha r>::iterator vcit = vc.begin();
std::vector<boo l>::iterator vbit = vb.begin();

*vcit = 'z'; // OK
*vbit = false; // OK

char *cp = &vc[0]; // OK
bool *bp = &vb[0]; // Oops: won't compile.

return 0;
}

On the other hand, it provides some operation specialized for bits that
std::vector<som ething-other-than-bool> does not. Josuttis 6.2.6 has the
gory details. If you can avoid the potholes, it may work fine for you.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #5
ok , thanks for you and Christopher. I will check that vector<bool>.

Hmm but I think cannot do bit operations for it:

vector<bool> a;

a |= 128;

The main point is, that I really need to be able to do similar operations
than bit operations to get some benefit in my code (That means, that set
*many* bits at the same time, as b |= 128 does). But maybe I can do it with
that vector ....

But anyway, it seems to be second best (better than normal arrays) if I
cannot use bit operations...

"Leor Zolman" <le**@bdsoft.co m> wrote in message
news:fk******** *************** *********@4ax.c om...
On Fri, 9 Apr 2004 10:33:24 +0100, "Juha Kettunen" <no*@valid.co m> wrote:
Hi

I don't know if I am using right words (bit-number), but this is what I
mean:

You can set a 64 bit number:

unsigned long a;


Just FYI, the number of bits in a long (unsigned or otherwise) is
platform-dependent. On my system they're only 32 bits. But that doesn't
have much bearing on your real question, which is how to get /real/ long
bit sequences.
How about if I want to get for example a 640 bit long *one* number (say b)and do the same binary operations to it (b |= 128)? I haven't found answerfor this ... do I need to use Bitfields:


For that, Christopher's suggestion of vector<bool> may be adequate.
vector<bool> is the "black sheep" of the STL container family...becaus e it
doesn't meet all the usual vector requirements:

#include <vector>

int main()
{
std::vector<cha r> vc;
std::vector<boo l> vb;

vc.push_back('x ');
vc.push_back('y ');
vb.push_back(tr ue);
vb.push_back(tr ue);

std::vector<cha r>::iterator vcit = vc.begin();
std::vector<boo l>::iterator vbit = vb.begin();

*vcit = 'z'; // OK
*vbit = false; // OK

char *cp = &vc[0]; // OK
bool *bp = &vb[0]; // Oops: won't compile.

return 0;
}

On the other hand, it provides some operation specialized for bits that
std::vector<som ething-other-than-bool> does not. Josuttis 6.2.6 has the
gory details. If you can avoid the potholes, it may work fine for you.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html

Jul 22 '05 #6
ok , thanks for you and Christopher. I will check that vector<bool>.

Hmm but I think cannot do bit operations for it:

vector<bool> a;

a |= 128;

The main point is, that I really need to be able to do similar operations
than bit operations to get some benefit in my code (That means, that set
*many* bits at the same time, as b |= 128 does). But maybe I can do it with
that vector ....

But anyway, it seems to be second best (better than normal arrays) if I
cannot use bit operations...

"Leor Zolman" <le**@bdsoft.co m> wrote in message
news:fk******** *************** *********@4ax.c om...
On Fri, 9 Apr 2004 10:33:24 +0100, "Juha Kettunen" <no*@valid.co m> wrote:
Hi

I don't know if I am using right words (bit-number), but this is what I
mean:

You can set a 64 bit number:

unsigned long a;


Just FYI, the number of bits in a long (unsigned or otherwise) is
platform-dependent. On my system they're only 32 bits. But that doesn't
have much bearing on your real question, which is how to get /real/ long
bit sequences.
How about if I want to get for example a 640 bit long *one* number (say b)and do the same binary operations to it (b |= 128)? I haven't found answerfor this ... do I need to use Bitfields:


For that, Christopher's suggestion of vector<bool> may be adequate.
vector<bool> is the "black sheep" of the STL container family...becaus e it
doesn't meet all the usual vector requirements:

#include <vector>

int main()
{
std::vector<cha r> vc;
std::vector<boo l> vb;

vc.push_back('x ');
vc.push_back('y ');
vb.push_back(tr ue);
vb.push_back(tr ue);

std::vector<cha r>::iterator vcit = vc.begin();
std::vector<boo l>::iterator vbit = vb.begin();

*vcit = 'z'; // OK
*vbit = false; // OK

char *cp = &vc[0]; // OK
bool *bp = &vb[0]; // Oops: won't compile.

return 0;
}

On the other hand, it provides some operation specialized for bits that
std::vector<som ething-other-than-bool> does not. Josuttis 6.2.6 has the
gory details. If you can avoid the potholes, it may work fine for you.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html

Jul 22 '05 #7

"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:c5******** **@chessie.cirr .com...
Juha Kettunen <no*@valid.co m> spoke thus:
How about if I want to get for example a 640 bit long *one* number (say b) and do the same binary operations to it (b |= 128)? I haven't found answer for this ... do I need to use Bitfields:


You might look at vector<bool>, although I have no idea how useful
you'll find it.


Actually, when I was checking from the "Stroustrup C++" this vector issue
just now, I recognized, that there is a std::bitset vector type as well,
which is definetely most suitable for me: It handles binary values and have
all of those bit operations |=, &=, and so on.

But thanks, i didnt really even think that vectors could solve my problem
.... (I thought i must be a struct).

I will try it now, and see if it *really* works :)...
Jul 22 '05 #8

"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:c5******** **@chessie.cirr .com...
Juha Kettunen <no*@valid.co m> spoke thus:
How about if I want to get for example a 640 bit long *one* number (say b) and do the same binary operations to it (b |= 128)? I haven't found answer for this ... do I need to use Bitfields:


You might look at vector<bool>, although I have no idea how useful
you'll find it.


Actually, when I was checking from the "Stroustrup C++" this vector issue
just now, I recognized, that there is a std::bitset vector type as well,
which is definetely most suitable for me: It handles binary values and have
all of those bit operations |=, &=, and so on.

But thanks, i didnt really even think that vectors could solve my problem
.... (I thought i must be a struct).

I will try it now, and see if it *really* works :)...
Jul 22 '05 #9
On Fri, 9 Apr 2004 13:35:19 +0100, "Juha Kettunen" <no*@valid.co m> wrote:

"Christophe r Benson-Manica" <at***@nospam.c yberspace.org> wrote in message
news:c5******* ***@chessie.cir r.com...
Juha Kettunen <no*@valid.co m> spoke thus:
> How about if I want to get for example a 640 bit long *one* number (sayb) > and do the same binary operations to it (b |= 128)? I haven't foundanswer > for this ... do I need to use Bitfields:


You might look at vector<bool>, although I have no idea how useful
you'll find it.


Actually, when I was checking from the "Stroustrup C++" this vector issue
just now, I recognized, that there is a std::bitset vector type as well,
which is definetely most suitable for me: It handles binary values and have
all of those bit operations |=, &=, and so on.


Yes, that's clearly a better starting point, and I'm kicking myself for
having forgotten about std::bitset. So as not to depart this thread without
having at least /something/ helpful to say, let me recommend that you get
yourself a copy of Josuttis' "The C++ Standard Library". It is
indispensable when trying to choose and then use STL facilities... and it
has ten pages on bitset.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: Download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #10

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

Similar topics

18
412
by: Juha Kettunen | last post by:
Hi I don't know if I am using right words (bit-number), but this is what I mean: You can set a 64 bit number: unsigned long a; Now you can use binary operators to manipulate variable a (for example
8
1908
by: Régis Troadec | last post by:
Hi all, I follow c.l.c. for only a short time and I would like to know why there isn't anything concerning bitfields among the FAQs. Is it because ... 1. of portability issues? 2. bitfields aren't enough useful to be discussed? 3. of the low frequency of questions concerning this topic? 4. of anything else?...
4
2108
by: Hipo | last post by:
Hi. My problem seems to be simple, but I can not figure out a solution. Problem: I have a number that consists of 128 bit. I want to compute its modulo (modulo is at the range < 2^16). So that there is no 128 bit datatype in C++ I just cannot imagine how I can work out qa solution for that. greets, Hipo
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9937
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3522
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.