byte

Bitwise AND, Bitwise Inclusive OR question, in Java

I've a few lines of code within a project, that I can't see the value of... buffer[i] = (currentByte & 0x7F) | (currentByte & 0x80); It reads the filebuffer from a file, stored as bytes, and then transfers then to buffer[i] as shown, but I can't understand what the overall purpose is, any ideas? Thanks ...

java bit manipulation

byte x = -1; for(int i = 0; i < 8; i++) { x = (byte) (x >>> 1); System.out.println("X: " + x); } As I understand it, java stores data in two's-complement, meaning -1 = 11111111 (according to wikipedia). Also, from the java docs: "The bit pattern is given by the left-hand operand, and the number of positions to shift by the r...

How to correctly convert filesize in bytes into mega or gigabytes?

I'm using the DriveInfo class in my C# project to retrieve the available bytes on given drives. How to I correctly convert this number into Mega- or Gigabytes? Dividing by 1024 will not do the job I guess. The results always differ from those shown in the Windows-Explorer. ...

Java (J2ME) Convert Image to byte[], then back to Image

Hey, I'm trying to convert an Image object to a byte array then back to an Image (so that I can store the image in a blob object in an Apache Derby Database). I can convert an Image to a byte array (code below) but I cann't convert the bytes back to an image. As a further complication I'm using J2ME, so I can't use javax.image.*. Can y...

Ruby: Length of a line of a file in bytes?

I'm writing this little HelloWorld as a followup to this and the numbers do not add up filename = "testThis.txt" total_bytes = 0 file = File.new(filename, "r") file.each do |line| total_bytes += line.unpack("U*").length end puts "original size #{File.size(filename)}" puts "Total bytes #{total_bytes}" The result is not the same as th...

Byte array of unknown length in java

I am constructing an array of bytes in java and I don't know how long the array will be. I want some tool like Java's StringBuffer that you can just call .append(byte b) or .append(byte[] buf) and have it buffer all my bytes and return to me a byte array when I'm done. Is there a class that does for bytes what StringBuffer does for S...

C#: Cannot convert from ulong to byte

Hello, Strange how I can do it in C++,but not in C#. To make it clear,i'll paste the two functions in C++ and then in C# and mark the problematic lines in the C# code with a comment "//error". What the two function does is encoding the parameter and then add it in to a global variable named byte1seeds. These are the functions in C++ ...

C# Problem using blowfish NET: How to convert from Uint32[] to byte[]

Hello, In C#,I'm using Blowfish.NET 2.1.3's BlowfishECB.cs file(can be found here) In C++,It's unknown,but it is similiar. In C++,the Initialize(blowfish) procedure is the following: void cBlowFish::Initialize(BYTE key[], int keybytes) In C#,the Initialize(blowfish) procedure is the same public void Initialize(byte[] key, int ofs,...

How to cast a dword into a byte array in C#

Hello, As you already may know,I'm migrating into C# and some things in C++ look different. C++ code BYTE packetBuffer[32] = {0}; *(LPWORD)(packetBuffer + 0) = 0xC; *(LPWORD)(packetBuffer + 2) = 0x5000; *(LPDWORD)(packetBuffer + 6) = dwArgs[13]; *(LPDWORD)(packetBuffer + 10) = *(keyArray2 + 0); *(LPDWORD)(packetBuffer + 14) =...

How to assign byte[] as a pointer in C#

Hello, I have a function that generates a CRC check byte based on the content of any packet.The problem is in translating the function from C++ to C# C++ code: unsigned char GenerateCheckByte( char* packet, int length, unsigned long seed ) { if( !packet ) return 0; unsigned long checksum = 0xFFFFFFFF; length &= 0x7FFF; char* ptr = pac...

Relation between word length, character size, integer size and byte

What is the relation between word length, character size, integer size, and byte in C++? ...

Representing char as a byte in Java

Hi all, I must convert a char into a byte or a byte array. In other languages I know that a char is just a single byte. However, looking at the Java Character class, its min value is \u0000 and its max value is \uFFFF. This makes it seem like a char is 2 bytes long. Will I be able to store it as a byte or do I need to store it as ...

Convert Byte Array into Bitset

I have a byte array generated by a random number generator. I want to put this into the STL bitset. Unfortunately, it looks like Bitset only supports the following constructors: A string of 1's and 0's like "10101011" An unsigned long. (my byte array will be longer) The only solution I can think of now is to read the byte array bit ...

How to write NSArray to NSOutputStream?

I want to send out an NSArray, so I have to write it to an NSOutputStream first. The method should be : - (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)length I can convert the array's pointer to uint8 _ t using : (uint8_t *)arr But how to get the length of bytes of the array? Do I have to save the array to a file an...

How can I convert bits to bytes?

I have an array of 128 booleans that represent bits. How can I convert these 128 bit representations into 16 bytes? Example: I have an array that looks like this: 0110001100110000100010111011001011010011010001010001101101001100 1000010000000000001000111111111101000011111001111011111011111001 (Converted to 1s and 0s to be more concis...

How to convert a double to hex?

Hello, How do I convert a ruby float/double to high endian order hex with high bytes and low bytes. EXAMPLE: start with 99.0 end up with 40 58 C0 00 00 00 00 00 high bytes low bytes ...

zlib from C++ to C#(How to convert byte[] to stream and stream to byte[])

Hello, My task is to decompress a packet(received) using zlib and then use an algoritm to make a picture from the data The good news is that I have the code in C++,but the task is to do it in C# C++ //Read the first values of the packet received DWORD image[200 * 64] = {0}; //used for algoritm(width always = 200 and height alway...

Fastest Method to Split a 32 Bit number into Bytes in C++

Hello all :) I am writing a piece of code designed to do some data compression on CLSID structures. I'm storing them as a compressed stream of 128 bit integers. However, the code in question has to be able to place invalid CLSIDs into the stream. In order to do this, I have left them as one big string. On disk, it would look something l...

How to use ICSharpCode.ZipLib with stream?

Hello, I'm very sorry for the conservative title and my question itself,but I'm lost. The samples provided with ICsharpCode.ZipLib doesn't include what I'm searching for. I want to decompress a byte[] by putting it in InflaterInputStream(ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream) I found a decompress function...

How to create a bmp file from byte[] in C#

Hello, I have a byte[] array received in TCP Client.The array contains a 24-bit RGB Bitmap file.How to create that bitmap file with given Width ,Height and data? In C++ I use this int WriteBitmapFile(const char *filename, int width, int height, unsigned char *imageData) { FILE *filePtr; // file pointer BITMAPFILEHEA...