473,385 Members | 1,712 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,385 software developers and data experts.

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 4682
"Søren Nøhr Christensen" <sn*@cs.auc.dk> 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_Keith) 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
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...
2
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) ...
43
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...
7
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...
0
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()...
3
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; ...
4
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 =...
7
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;...
2
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 ! ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.