From: jazir Newsgroups: comp.os.msdos.djgpp Subject: Re: Length of Chars... Date: Sun, 23 Jan 2000 20:22:49 +1100 Organization: Optus Internet Lines: 38 Message-ID: <388AC869.866CAC0F@mpx.com.au> References: <3888ED7B DOT DF52FEB2 AT ou DOT edu> <38896068 DOT 8C5927C0 AT is DOT elta DOT co DOT il> <388A0530 DOT DF2B2F31 AT ou DOT edu> NNTP-Posting-Host: wdcax2-086.dialup.optusnet.com.au Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news1.mpx.com.au 948622622 1216 198.142.247.86 (23 Jan 2000 10:17:02 GMT) X-Complaints-To: abuse AT mpx DOT com DOT au NNTP-Posting-Date: 23 Jan 2000 10:17:02 GMT X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com hey david and everyone, David Cleaver wrote: > OK, I'll explain a little 'bit' more. :) I'm writing a program to > factor numbers, hopefully, very quickly. Now, in order to do this I > have created a bunch of two dimensional arrays whose elements only > consist of zero's and one's. Since this is the case, I decided to > reduce the size of the array from using an int for each zero or one, and > have packed all the zero's and one's into unsigned char's. As you can > see, this greatly reduced the amount of storage needed.... i think there is a better way to do it that wouldn't really matter what type you used for each element. but say you used an unsigned char, which is 8-bits..you could store 8-bits {funnily enough} in one char, and access them using the bit-shift (>> and <<) operators. the binary arithmetic takes a bit of getting used to, but it will mean you aren't wasting *any* space, except for a few bits that might be unused in the very last char. i'm not sure it's useful, but i have code that defines "bitstrings" that provide operations to extend by a bit, and to take bits from the stream. these can only have length up to the size of an unsigned long, but there is also code for "bitstreams", that can write/read a series of bits to/from a file. the bitstrings aren't all that space-efficient, because each one has to store how many bits are currently in use, but the bitstreams do not need this, as they only actually write to the file after each unsigned long is full of information. you could tailor the bitstream code so that it uses yr 2D-array rather then a file. this would take 8-times less space then yr current approach {assuming i understand it properly} :) if yr interested in this approach, u can e-mail me for more information. if you would rather not use my code, i'm sure u could do it all with the bitshift operators :) hope this helps, daniel.