473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The size of a bitarray??

Hi all!
I was wondering how much overhead was involved in using a bitarray. In
other words, how much space does an array of say 32bit use?

snc

Nov 13 '05 #1
2 4703
"Søren Nøhr Christensen" <sn*@cs.auc.d k> wrote in message
news:bl******** **@sunsite.dk.. .
Hi all!
I was wondering how much overhead was involved in using a bitarray.
C does not define anything called a "bitarray".
In
other words, how much space does an array of say 32bit use?


The smallest unit of storage in C is a byte, expressed
with type 'char', 'unsigned char', or 'signed char'.
These types are required to contain a minimum of eight
bits, but are allowed to contain more. The number of
bits in a byte can be determined with the 'CHAR_BIT'
macro (this value need not be the same for all
implementations ).

The individual bits of an object cannot be directly
addressed (but can be examined and modified with the
bitwise operators, e.g. & and | ).

Arrays of any type can be created.
The amount of memory consumed by an array is the product
of the number of array elements and the array element size,
in bytes. The size each of the character types is one, by
definition. The size of any type can be determined using the
'sizeof' operator.

char array[100]; /* array consumes 100 bytes, or 100 * CHAR_BIT bits */

int array[100]; /* array consumes 100 * sizeof(int) bytes, or
100 * sizeof(int) * CHAR_BIT bits */

The macro CHAR_BIT is declared by the standard header
<limits.h>
Ever considered reading a book about C?

-Mike
Nov 13 '05 #2
> I was wondering how much overhead was involved in using a bitarray. In
other words, how much space does an array of say 32bit use?


I don't know. What's a "bitarray"? C doesn't directly support such
a concept, but there are a number of ways you can implement an array
of bits.

If you have some particular implementation in mind, post some (small)
sample code and we can answer any questions you might have about it.
If you don't know how to implement an array of bits in C, we can help
you with that; I suspect there are libraries out there that can do
what you want. The underlying implementation would most likely involve
explicit shifting and masking.

--
Keith Thompson (The_Other_Keit h) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #3

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

Similar topics

1
4011
by: Ramzi Abboud | last post by:
I want to store a binary string in SqlServer from VB .NET through a stored procedure. I have been storing the binary data in a BitArray which I am not set on by any means. When I pass the BitArray into a stored procedure, which is looking for a variable of type binary, it throws the following: "Object must implement IConvertible." BitArray...
2
8914
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) outputBank(0) = True outputBank(1) = False outputBank(2) = False
43
3722
by: Vladimir | last post by:
Method UnicodeEncoding.GetMaxByteCount(charCount) returns charCount * 2. Method UTF8Encoding.GetMaxByteCount(charCount) returns charCount * 4. But why that? Look: /* Each Unicode character in a string is defined by a Unicode scalar value, also called ...
7
7586
by: Eric | last post by:
Hi All, I need to XOR two same-length Strings against each other. I'm assuming that, in order to do so, I'll need to convert each String to a BitArray. Thus, my question is this: is there an easy way to convert a String to a BitArray (and back again)? I explained the ultimate goal (XORing two Strings) so that, if anyone has a better...
0
1162
by: James | last post by:
Hi, I need to use an array of bitarray and being able to dinamically redim the bitarray and the array of bitarray. I need something like: structure stBarray public BA as bitarray() endstructure dim Array() as stBarray so I can:
3
2197
by: HKannen | last post by:
Hello Everybody, I wrote a little method that gets me an Int32 from a BitArray. This method looks like this: private Int32 GetIntVal( BitArray iArray ) { Byte lByteArr = new Byte; iArray.CopyTo( lByteArr, 0 );
4
3834
by: Rainer Queck | last post by:
Hi NG I have some questions concerning BitArrays. Assumption : BitArray with 16 Bits Is it possible to "load" a BitArray with a UInt16 Value with out iterating it like: UInt16 Bits = 0xAA55; for (int i = 0 ; i<16 ; i++){
7
2416
by: Rick Williams | last post by:
I was so happy to find the BitArray class. Until I 'cut and pasted' the following sample code from Visual Studio's help: #using <mscorlib.dll> #using <system.dll> using namespace System; using namespace System::Collections;
2
2834
by: semedao | last post by:
Hi , I try the BitArray class to make Xor on 2 byte arrays. The result was that when I Xor 1with 2 I get 3 which is correct then Xoring 3 with 1 give me 0 (zero) when it should give me 2 ! but Xoring 3 with 2 give 2 which is correct... (should be 1) here is the sample code...
0
7915
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
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. ...
1
7967
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...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5712
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...
1
2347
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
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
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...

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.