byte

Structures in C.

I got a structure like this: struct bar { char x; char *y; }; I can assume that on a 32 bit system, that padding for char will make it 4 bytes total, and a pointer in 32 bit is 4, so the total size will be 8 right? I know it's all implementation specific, but I think if it's within 1-4, it should be padded to 4, within 5-8 to...

How to convert an integer to variable length byte string?

I want to convert an integer (int or long) a big-endian byte string. The byte string has to be of variable length, so that only the minimum number of bytes are used (the total length length of the preceding data is known, so the variable length can be inferred). My current solution is import bitstring bitstring.BitString(hex=hex(456))...

copy a stream via byte[]

Hiho, i have to copy an inputstream. And after a bit of searching in the net, i tried this with the help of a bytearray. My code looks like this("is" is the inputstream): ByteArrayOutputStream bos = new ByteArrayOutputStream(); while (is.read() != -1) { bos.write(is.read()); } byte[] ba = bos.toByteArray(); ...

How to Convert.ToByte[] sql reader?

I am saving a image into database with byte[] property like this: ProfileModel: private byte[] _imageData; public byte[] ImageData { get { return _imageData; } set { _imageData = value; } } When I am trying to read image i have problem with converting of byte. I dont know how to convert reader...

Converting bytes to a binary string in c#

In c# I am converting a byte to binary, the actual answer is 00111111 but the result being given is 111111. Now I really need to display even the 2 0s in front. Can anyone tell me how to do this? I am using: Convert.ToString(byteArray[20],2) and the byte value is 63 ...

BitmapFactory.decodeStream(inputStream) always return null when some bytes are wrong.

Hi there! I'm building an android app and I'm currently having trouble retrieving a bitmap from an URL. Here is the code I'm using : public static Bitmap bmpFromURL(URL imageURL){ Bitmap result = null; try { HttpURLConnection connection = (HttpURLConnection)imageURL .openConnection(); connection.setDoInput(t...

How many bytes per inodes?

HI, I need to create a very high number of files which are not very large (like 4kb,8kb). It's not possible on my computer cause it takes all inodes up to 100% and I cannot create more files : -bash-4.0$ df -i /dev/sda5 Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda5 54362112 36381206 17980906 67% /...

Why is the range of bytes -128 to 127 in Java?

OK, this is as noob as it gets, but I still don't get why the lowest value a byte can take is -128. That the highest value is 127 I can understand, because it's 01111111 in binary, but how does one represent -128 with only 8 bit, one of which is used for the sign? Positive 128 would already be 8-bit, i.e. 10000000, and then you need a 9t...

How to download by block with Qt ?

For many reasons i need to download file by piece of 1024 byte. I find nothing in QnetworkAccessManager. I can not use the "header technic" because my server don't support it. I call header technic, the tecnic who send stuff like "Content-Range: bytes 21010-47000/47022" in the header of http request ...

C# int byte conversion

Why is byte someVar; someVar -= 3; valid but byte someVar; someVar = someVar - 3; isnt? ...

Python: find most frequent bytes?

I'm looking for a (preferably simple) way to find and order the most common bytes in a python stream element. e.g. >>> freq_bytes(b'hello world') b'lohe wrd' or even >>> freq_bytes(b'hello world') [108,111,104,101,32,119,114,100] I currently have a function that returns a list in the form list[97] == occurrences of "a". I need th...

Packing ints to bytes (NSData)

I want to pack a MIDI message into an NSData object. int messageType = 3; // 0-15 int channel = 5; // 0-15 int data1 = 56; // 0-127 int data2 = 78; // 0-127 int packed = data2; packed += data1 * 127; packed += channel * 16129; // 127^2 packed += messageType * 258064; // 127^2 * 16 NSLog(@"packed %d", packed); NSData ...

Find number of bytes a particular Hash is using in Ruby

All I want to know is how many bytes Ruby is using for a particular Hash object. How do I do that? ...

C#: UDP Socket - Receive data with unknown size

Hi, i use a UDP-socket for sending/receiving objects. I serialize the objects into a byte array send it and receive it with a client. But before i can receive i have to allocate a byte array. I must do it before and then handle the Socket.Receive()-methode the array. But my objects have a variable length. How can i discover the array-si...

Display bytes in NSLog

Hi there How can I display these bytes in NSLog? const void *devTokenBytes = [devToken bytes]; Cheers Cyril ...

WPF - 'Stride' Woes from a TransformedBitmap Object.

I have a 2208 x 3000 TransformedBitmap object with format {Indexed8} that I'm do .CopyPixels() on. I'm using (int)((formattedBitmap.PixelWidth * formattedBitmap.Format.BitsPerPixel + 7) / 8) (assuming 'formattedBitmap' is the name of the image from which I'm trying to copy the pixels) for the 'stride' value in my method call and an ...

How to make an Encode function based on this Decode function?

How to make an Encode function based on this Decode function? I got the source code for the Decode function on the internet but I need the Encode function. All my attempts to make it failed and the original coder isn't available at the moment. The (original) code: byte Decode(byte EncodedByte) { EncodedByte ^= (byte)194; Encod...

C++ 2.5 bytes (20-bit) integer

I know it's ridiculous but I need it for storage optimization. Is there any good way to implement it in C++ ? It has to be flexible enough so that I can use as normal data type e.g Vector< int20 >, operator overloading etc.. ...

Java: object to byte[] and byte[] to object converter (for Tokyo Cabinet)

I need to convert objects to a byte[] to be stored in the Tokyo Cabinet key-value store. I also need to unbyte the byte[] to an Object when reading from the key-value store. Are there any packages out there that will help me with this task? Or would the best solution to implement it myself? ...

[Java] I/O why does a byte can represent a character?

and i see the character are only ASCII then its not dynamic right? any explanation for this? other question, what is the difference between byte streams and character streams? ...