bits

C++: a scalable number class - bitset<1>* or unsigned char*

試著忘記壹切 提交于 2019-12-12 01:06:53
问题 I'm planning on creating a number class. The purpose is to hold any amount of numbers without worrying about getting too much (like with int, or long). But at the same time not USING too much. For example: If I have data that only really needs 1-10, I don't need a int (4 bytes), a short(2 bytes) or even a char(1 byte). So why allocate so much? If i want to hold data that requires an extremely large amount (only integers in this scenario) like past the billions, I cannot. My goal is to create

Convert the bytes of byte array to bits and store in Integer array

馋奶兔 提交于 2019-12-11 19:34:01
问题 I have bytes in a byte array. I need to store the bit value of each byte in an integer array . For example , the byte array is byte HexToBin[] = {(byte)0x9A, (byte)0xFF,(byte) 0x05,(byte) 0x16}; then the integer array should have a = [10011010111111110000010100010110] I have tried the following code, where i was able to print the binary value of each byte (s2) but i couldnot store in integer array allBits. byte hexToBin[] = {(byte)0x9A, (byte)0xFF,(byte) 0x05,(byte) 0x16}; int[] allBits = new

What is the meaning of `16 longs` and `110 words`, when reads the bits from a file

微笑、不失礼 提交于 2019-12-11 18:08:02
问题 I'm trying to read PUD file format, that belong to the warcraft 2 game map. In the explanation of file structure, there is small phrases I don't understand it. What is this mean ( 16 longs , 110 words ) ? Here is an example 16 longs -------> Units and buildings allowed. (16 players) units bit order: 0000000000000000000000000000000x bit0: footman/grunt 000000000000000000000000000000x0 bit1: peasant/peon 00000000000000000000000000000x00 bit2: ballista/catapult 0000000000000000000000000000x000

Check number of bits on in ax [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-11 17:31:09
问题 This question already has answers here : Hamming weight ( number of 1 in a number) mixing C with assembly (4 answers) How to count the number of set bits in a 32-bit integer? (53 answers) Closed 2 years ago . i need to find a way to check number of bits that is current on (1) in the ax register. i was thinking to use in shl or shr, but i do not know how exactly i suppose to use them. this is my code so far: org 100h mov ax, 0xffffh ;shr ax TO DO int 16h ret i red in some place that the shift

Compare two hex strings to find number of matching bits

China☆狼群 提交于 2019-12-11 11:27:48
问题 I have two hex strings: string x = "928fe46f228555621c7f42f3664530f9"; string y = "56cd8c4852cf24b1182300df2448743a"; I'm trying to convert them to binary to find how many bits matches between the two hex strings. I used this function to convert HEX to Binary: string GetBinaryStringFromHexString (string sHex) { string sReturn = ""; for (int i = 0; i < sHex.length (); ++i) { switch (sHex [i]) { case '0': sReturn.append ("0000"); break; case '1': sReturn.append ("0001"); break; case '2':

Java: reading a variable number of bits and converting to an integer

China☆狼群 提交于 2019-12-11 09:04:14
问题 I need to write a method which reads a variable number of bits from a Byte Buffer and converts those bytes into a primitive int or long (if more than 32 bits). I am not very proficient at working with bits, but I did look at some code examples and answers to similar(ish) questions and here is the best that I could come up with ( bb refers to an internal ByteBuffer ): public int readBits(int number) { int initialPosition = bb.position(); int value = 0; int remaining = number; int position = bb

Boost dynamic_bitset - put an integer value into a range of bits

泄露秘密 提交于 2019-12-11 01:46:37
问题 I have a 7-byte/56-bit bitset that upon construction sets the first bit to one: boost::dynamic_bitset<> b(56, 1); After construction, I'd like to place an integer value (say 2019) into bits 4 through 15. I'm curious if there is a simple way within boost to do this without bitwise operations? Basically, I want to set a range of bits to an integer value that I know is small enough to fit into those bits. Thanks for any advice. 回答1: The boost::dynamic_bitset<> offers much less functionality. I

64 bits application starting 32 bits process

孤街醉人 提交于 2019-12-10 19:47:01
问题 I'm working on a 64 bits application coded with .Net 4.0, C#. In this application, at some point, I need to start another exe file using the following code : l_process.StartInfo.FileName = _sFullFilePath; l_process.StartInfo.Verb = "Open"; l_process.StartInfo.CreateNoWindow = true; l_process.StartInfo.Arguments = l_sParams; l_process.Start(); Now, this external application being compiled under 32 bits environment (x86), I get the following error : **The specified executable is not valid for

How to write bits to a file?

六眼飞鱼酱① 提交于 2019-12-10 15:44:15
问题 How to write bits (not bytes) to a file with c#, .net? I'm preety stuck with it. Edit : i'm looking for a different way that just writing every 8 bits as a byte 回答1: The smallest amount of data you can write at one time is a byte. If you need to write individual bit-values. (Like for instance a binary format that requires a 1 bit flag, a 3 bit integer and a 4 bit integer); you would need to buffer the individual values in memory and write to the file when you have a whole byte to write. (For

Calculating the maximum size of a signed integer

江枫思渺然 提交于 2019-12-10 09:46:26
问题 I wanted to know what the maximum value my time_t can hold was, so I wrote a little program helping me. It needs one argument: the amount of bytes (1 byte = 8 bits). So I wrote it and tested it. It goes well by all values from 1 untill 4, but at 5 and higher it also edits the "signed"-bit (I don't know how it's called). Can someone explain: #include <stdio.h> int main(int argc, const char **argv) { if(argc != 2) { fprintf(stderr, "Usage: %s bits/8\n", argv[0]); return -1; } unsigned int bytes