byte

Unexpected long process time when reading a byte array

I have a program that need to handle byte array source. Originally the program work fine when the byte array size is 3000 byte. Now data size increase and the array size need to be changed from 3000 to 30000 (10 times). I make a sample benchmark program to test looping time. I suppose required CPU time should be increase linearly acc...

Understanding Java unsigned numbers

I want to understand how to convert signed number into unsigned. lets say I have this: byte number = 127; // '1111111' In order to make it unsigned I have to choose "bigger" data type 'short' and apply AND operator with value 0x00ff. short number2; number2 = number & 0x00ff; Why does it make the number unsigned? ...

Python method for storing list of bytes in network (big-endian) byte order to file (little-endian)

My present task is to dissect tcpdump data that includes P2P messages and I am having trouble with the piece data I acquire and write to a file on my x86 machine. My suspicion is I have a simple endian-ness issue with the bytes I write to to file. I have a list of bytes holding a piece of P2P video read and processed using python-pcapy...

Byte datatype in Objective C in iPhone

Hi friends, I want to send the bytes to the server. So i donno Which data types is used for bytes. I have used "%s" and sent the bytes to the server. But In server side they have received 6 bytes only. But my case i want to send 32 bytes to the server. So Which data type is used for that? EDIT:- Here my sample code is, -(void)sendDe...

Python base64 data decode and byte order convert

Hi, I am now using python base64 module to decode a base64 coded XML file, what I did was to find each of the data (there are thousands of them as for exmaple in "ABC....", the "ABC..." was the base64 encoded data) and add it to a string, lets say s, then I use base64.b64decode(s) to get the result, I am not sure of the result of the dec...

How can you Marshal a byte array in C#?

I'm trying to call the following C++ function that's wrapped up into a DLL: unsigned char * rectifyImage(unsigned char *pimg, int rows, int cols) My import statement looks like the following: [DllImport("mex_rectify_image.dll")] unsafe public static extern IntPtr rectifyImage( byte[] data, int rows, int columns); And my call routi...

Error "This stream does not support seek operations" in C#

Hi, I'm trying to get an image from an url using a byte stream. But i get this error message: This stream does not support seek operations. This is my code: byte[] b; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); WebResponse myResp = myReq.GetResponse(); Stream stream = myResp.GetResponseStream(); int i; using (Bina...

C# strange code

Anyone know what follow code does? the question is about follow operators: & and |,and 0xfc salt[0] = (byte)((salt[0] & 0xfc) | (saltLen & 0x03)); salt[1] = (byte)((salt[1] & 0xf3) | (saltLen & 0x0c)); salt[2] = (byte)((salt[2] & 0xcf) | (saltLen & 0x30)); salt[3] = (byte)((salt[3] & 0x3f) | (saltLen & 0xc0)); ...

C style char arrays - How many bytes do we store?

char firstName[32]; I understand that each char occupies 1 byte in memory. So does the above occupy 32 bytes of memory? Am I missing a pointer that takes up memory too or is this just 32 bytes? ...

Question on how to copy a byte array buffer to a byte pointer in Visual C++...

Hello all. I'm posting my first question here after having viewed many useful exchanges by others; it's very exciting! I'm thinking that this question will be fairly straightforward to answer, but I hope that someone can shed some light on it since its vexing me. I have a function that accepts an array of bytes passed in as a byte p...

Delphi: Convert a TByte into its corresponding Hex-Value in AnsiString

Hello everybody, I'm trying to output the value of a TByte as its corresponding hexadezimal representation in an AnsiString. Example: TByte is 0x4F AnsiString: "4F" (two characters, a 4 and an F) I know of the StringOf function, but that converts to the "mapped" character. Is there any decent function build in or does somebody has a ...

Should I be comparing bytes using struct?

I'm trying to compare the data within two files, and retrieve a list of offsets of where the differences are. I tried it on some text files and it worked quite well.. However on non-text files (that still contain ascii text), I call them binary data files. (executables, so on..) It seems to think some bytes are the same, even though whe...

C# Encounter a problem when convert byte[] to struct. The byte order is wrong.

I was trying to using struct to parse socket data when implement a UDP based protocol. And I searched and I can use these 2 functions to convert between byte[] and struct: byte[] StructToBytes(object structObj) { int size = Marshal.SizeOf(structObj); IntPtr buffer = Marshal.AllocHGlobal(size); try { ...

How to store mp3 as bytes in sql server

Possible Duplicate: how to read and write MP3 to database Hi I need to read and store mp3 files as bytes in sql server and C#.. How can I do that? ...

Fields in a struct skipping bytes

Hey guys, I have a struct I have written which is supposed to represent an entire UDP packet, with the ethernet header and all. Here it is: #pragma pack(1) struct UDPPacket { // an array to hold the destination mac address of the packet unsigned char dstmac[6]; // an array to hold the source mac address of the packet un...

Storing 4 bits from a byte in VB.Net

What is the best way to store 4 bits from a byte in VB.Net? Where best means: Most straightforward method of storage from a Byte type. The easiest to work with while performing bitwise operations. Straightforward conversion of the bits to other types. Storing them in a BitArray via it's constructor reverses the order of the bits. This m...

Reading data from a Smart Card (preferably with Java)

I would like to be able to read a few bytes of unencrypted data which is stored in a smart card. I have the reader and know that the Sun version of Java 6 includes javax.smartcardio and I have read a bit about these APIs. Having never worked with smart cards before I wonder if there is a simple way to read bytes of date in a given secto...

How to convert byte string into Number?

Hi all, I have a string encoded in Little Endian format (least-significant-byte first), and I want to decode it into a Number. For the encoder, the first bit of the last byte reflects whether the number is positive or negitive. Does anyone know how to do this? Here's my decoder: decode:function(str,type){ var num=0; va...

How to turn byte[] into sbyte* in C#?

I have a function that want to receive sbyte* buffer how to create such in C# from scratch and from existing byte[]? ...

What is the C++ analog of C# byte[]?

What is the C++ (and or visual-C++) analog of C# byte[]? ...