byte

Efficient arbitrary-sized integer packing in Python

The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()). ...

D2009 problems with array of char - how can I `elegantly` fix my code?

Going through some of my older Delphi projects and upgrading them to D2009, as I find this version a great improvement (Generics.Collections - wow! ;)) to all previous releases, I encounter various problems. This one I managed to solve but the solution does not seem half as elegant as I believe it could be. (Note, I haven't written Delph...

How to interpret binary data in C++?

I am sending and receiving binary data to/from a device in packets (64 byte). The data has a specific format, parts of which vary with different request / response. Now I am designing an interpreter for the received data. Simply reading the data by positions is OK, but doesn't look that cool when I have a dozen different response forma...

Convert base64 encoded string to java byte array

I am writing a decryption class (AES/CBC/PKCS7Padding) where the encrypted data is coming from C#. I want to take the following string (which is base64 encoded): usiTyri3/gPJJ0F6Kj9qYL0w/zXiUAEcslUH6/zVIjs= and convert it to a byte array in java to pass into the SecretKeySpec as the key. I know there is the issue of C# having unsigned ...

Byte array in objective-c

How can create a byte array in objective c programming ... i have the data that is "0x12,0x23,0x34,0x45,0x56,0x67,0x78,0x89,0x12,0x23,0x34,0x45,0x56,0x67,0x78,0x89" i want it prepare as a byte array... pls help me.. ... if anybody have any sample project.. pls give me... ...

byte[] to string to byte array conversion did not work fine in java

I have a byte array initialised like this: public static byte[] tmpIV = {0x43, (byte)0x6d, 0x22, (byte)0x9a, 0x22, (byte)0xf8, (byte)0xcf, (byte)0xfe, 0x15, 0x21, (byte)0x0b, 0x38, 0x01, (byte)0xa7, (byte)0xfc, 0x0e}; If I print it it gives me 67 109 34 -102 34 -8...

Ensure number is cast correctly in .NET

I know that I can assign a value specifically to a float by doing float y = 4.5f; I want to do the same thing, except as a byte. How do I do this? I've checked the MSDN documentation and cannot find anything related to this. Also, what is this called? Thanks, [Edit] For clarity the code I'm using this on is byte myByte = a==b?1:0;...

Insert One Bit into Byte Array

Hello, I'm trying to insert a single bit into an array of bytes, which would shift all the bits in the byte array to the left. Say I have a Java byte array as follows: byte[] byteArray = new byte[2]; byteArray[0] = 0x11 byteArray[1] = 0x00 In binary, this byte array represented as: 0001 0001 0000 0000 Now I want to insert a zero ...

Is there a better way than int( byte_buffer.encode('hex'), 16 )

In Python, I'm constantly using the following sequence to get an integer value from a byte buffer (in python this is a str). I'm getting the buffer from the struct.unpack() routine. When I unpack a 'char' using byte_buffer, = struct.unpack('c', raw_buffer) int_value = int( byte_buffer.encode('hex'), 16 ) Is there a better way? ...

Why is a cast required for byte subtraction in C#?

I have to following code in VS2008 .net 3.5 using WinForms: byte percent = 70; byte zero = 0; Bitmap copy = (Bitmap)image1.Clone(); ... Color oColor = copy.GetPixel(x, y); byte oR = (byte)(oColor.R - percent < zero ? zero : oColor.R - percent); When I leave the "(byte)" off the last line of code, I get a compiler error saying it "Ca...

C# bitmap images, byte arrays and streams!

I have a function which extracts a file into a byte array (data). int contentLength = postedFile.ContentLength; byte[] data = new byte[contentLength]; postedFile.InputStream.Read(data, 0, contentLength); Later I use this byte array to construct an System.Drawing.Image object (where data is the byte array) ...

Convert Bytes to bits

Hi, I'm working with java. I have a byte array (8 bits in each position of the array) and what I need to do is to put together 2 of the values of the array and get a value. I'll try to explain myself better; I'm extracting audio data from a audio file. This data is stored in a byte array. Each audio sample has a size of 16 bits. If t...

Ruby: create a String from bytes

I would like to build a string from a byte value. I currently use: str = " " str[0] = byte This seems to work fine but I find it ugly and not very scalable to strings longer than 1 character. Any idea? ...

PHP Bytes 2 DWord

I have an array: $arr[0] = 95 $arr[1] = 8 $arr[2] = 0 $arr[3] = 0 That are bytes. I need a DWORD. I tried: $dword = $arr[0]+$arr[1]*265+$arr[2]*265*265+$arr[3]*265*265*265; Is that right or am I doing it wrong? ...

MemoryStream vs an array of bytes.

Hi; While using a MemoryStream, I find myself often copying (hence duplicating) data to a temporary array of bytes. I think it's a little bit of a waste of ressource, because MemoryStream dosen't let you directly access the underlying byte array. In this situation, what's the real advantage of a MemoryStream? I have read somewhere tha...

Why can't I do boolean logic on bytes?

In C# (3.5) I try the following: byte byte1 = 0x00; byte byte2 = 0x00; byte byte3 = byte1 & byte2; and I get Error 132: "Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)". The same happens with | and ^. What am I doing wrong? Why is it asking me about ints? Why can't I do bool...

Snippet Clarification byte array to port number

I have a byte array that contains 6 bytes last 2 represents the port number while searching for a way two convert these last to bytes to a port number i have come across this snippet, int port = 0; port |= peerList[i+4] port <<= 8; port |= peerList[i+5] it works but i need some clarification as to how it w...

Byte Serving PDFs from SQL varbinary

Hi I am want to take advantage of the web optimization for pdfs by allowing users to download them a page at a time. The pdfs are configured for fast web view. I am serving the pdfs from sql server 2008. The c# .net 3.5 web app untilises linq to SQL to load the files into a binary array from the database. The file is opended in PDF ...

Java Iterate Bits in Byte Array

How can i iterate bits in a byte array? ...

Saving JPEG screenshot as a BYTE buffer in C

In one of my previous questions I asked how to take a screenshot and save it as JPEG without the use of GDI+ due to the constrains of having to use only C. At the end I answered the question myself with the help of of some of the comments there. Using a very terse C version of GDI+ (loaded at runtime) i can take a screenshot and save it...