bits

Generate all binary strings of length n with k bits set

What's the best algorithm to find all binary strings of length n that contain k bits set? For example, if n=4 and k=3, there are... 0111 1011 1101 1110 I need a good way to generate these given any n and any k so I'd prefer it to be done with strings. ...

How can I tell when a download is complete using SharpBits in VB.NET?

I have a very basic windows forms app. it needs to download some files in the background. How can I tell when the download is done?? Here is what I have: Dim bits As New SharpBits.Base.BitsManager Dim mynewjob As SharpBits.Base.BitsJob = _ bits.CreateJob("jobname", SharpBits.Base.JobType.Download) mynewjob.AddFile("ht...

Background Intelligent Transfer Service and Amazon S3.

Hi I'm using SharpBITS to download file from AmazonS3. > // Create new download job. BitsJob > job = this._bitsManager.CreateJob(jobName, JobType.Download); > // Add file to job. > job.AddFile(downloadFile.RemoteUrl, downloadFile.LocalDestination); > // Resume > job.Resume(); It works for files which do no need authentication. Howeve...

Comparing set of bits in byte array

Hello! I have a byte array, as follows: byte[] array = new byte[] { 0xAB, 0x7B, 0xF0, 0xEA, 0x04, 0x2E, 0xF3, 0xA9}; The task is to find the quantity of occurrences '0xA' in it. Could you advise what to do? The answer is 6. ...

Retrieving dll version info via Win32 - VerQueryValue(...) crashes under Win7 x64

The respected open source .NET wrapper implementation (SharpBITS) of Windows BITS services fails identifying the underlying BITS version under Win7 x64. Here is the source code that fails. NativeMethods are native Win32 calls wrapped by .NET methods and decorated via DllImport attribute. private static BitsVersion GetBitsVersion() ...

Does .NET have a BITS module?

I have been researching in to using Background Intelligent Transfer Service. Most articles I have seen says there is no official .NET port but they recommend using sharpBITS. I will use sharpBITS if I have to but I noticed that all of the articles are referencing .NET 1.1 and 2.0, they seem to have been written before 3.0 came out. Was B...

color depth bits?

(Quick version: jump to paragraph next to the last one - the one beginning with "But") I was happy in my ignorance believing that PVRTC images were 4 or 2 bits per channel. That sounded plausible. It would give 4+4+4+4 (16 bit) or 2+2+2+2 (8 bit) textures, that would have 2^16 (65536) and 2^8 (256) color depth respectively. But reading ...

BITS client fails to specify HTTP Range header

Our system is designed to deploy to regions with unreliable and/or insufficient network connections. We build our own fault tolerating data replication services that uses BITS. Due to some security and maintenance requirements, we implemented our own ASP.NET file download service on the server side, instead of just letting IIS serving u...

What is the max possible size of an 32x32px .ico file?

Titles says it all. I'm making a favicon.ico script, and i need to know the max amount of bits possible. ...

given two bits in a set of four, find position of two other bits

hello I am working on a simple combinatorics part, and found that I need to recover position of two bits given position of other two bits in 4-bits srring. for example, (0,1) maps to (2,3), (0,2) to (1,3), etc. for a total of six combinations. My solution is to test bits using four nested ternary operators: ab is a four bit string, wi...

Looking for a clear and concise web page explaining why lower bits of random numbers are usually not that random.

I am putting together an internal "every developer should know" wiki page. I saw many discussions regarding rand() % N, but not a single web page that explains it all. For instance, I am curious if this problem is only C- and Linux-specific, or if it also applies to Windows, C++,. Java, .Net, Python, Perl. Please help me get to the bo...

Using Python How can I read the bits in a byte?

I have a file where the first byte contains encoded information. In Matlab I can read the byte bit by bit with var=fread(file,8, 'ubit1') then retrieve each bit by var(1),var(2), etc. Is there any equivalent bit reader in python? ...

How is 6 trits equal to 9.5 bits?

This reddit thread says 6 trits ~ 9.5 bits. How is 6 trits ~ 9.5 bits? ...

Why is it useful to count the number of bits?

I've seen the numerous questions about counting the number of set bits in an insert type of input, but why is it useful? For those looking for algorithms about bit counting, look here: http://stackoverflow.com/questions/1517848/counting-common-bits-in-a-sequence-of-unsigned-longs http://stackoverflow.com/questions/472325/fastest-way-t...

How to count bits for a number in Python?

1 -> 1 5 -> 3 10 -> 4 100 -> 7 1000 -> 10 How to count bits for a number in Python? ...

Swap bits in c++ for a double

Im trying to change from big endian to little endian on a double. One way to go is to use double val, tmp = 5.55; ((unsigned int *)&val)[0] = ntohl(((unsigned int *)&tmp)[1]); ((unsigned int *)&val)[1] = ntohl(((unsigned int *)&tmp)[0]); But then I get a warning: "dereferencing type-punned pointer will break strict-aliasing rules" an...

In C, would !~b ever be faster than b == 0xff ?

From a long time ago I have a memory which has stuck with me that says comparisons against zero are faster than any other value (ahem Z80). In some C code I'm writing I want to skip values which have all their bits set. Currently the type of these values is char but may change. I have two different alternatives to perform the test: if ...

java help bitwise operations

System.out.println( s + ", long: " + l + ", binary: "); System.out.print(" "); for(int i = 63; i >= 0; i--) if(((1L << i) & l) != 0) System.out.print("1"); else System.out.print("0"); System.out.println(); ...

python convert 12 bit image encoded in a string to 8 bit png

I have a string that is read from a usb apogee camera that is a 12-bit grayscale image with the 12-bits each occupying the lowest 12 bits of 16-bits words. I want to create a 8-bit png from this string by ignoring the lowest 4 bits. I can convert it to a 16-bit image where the highest 4 bits are always zero using PIL with import Image...

Inserting bits into byte

I was looking at an example of reading bits from a byte and the implementation looked simple and easy to understand. I was wondering if anyone has a similar example of how to insert bits into a byte or byte array, that is easier to understand and also implement like the example below. Here is the example I found of reading bits from a ...