byte

C#: Implementing NetworkStream.Peek?

Currently, there isn't a NetworkStream.Peek method in C#. What is the best way of implementing such a method which functions just like NetworkStream.ReadByte except that the returned byte is not actually removed from the Stream? ...

Sending struct via Socket using JAVA and C++

I have a socket where server is in JAVA but Client is in C++. Struct{ float length; char[] name; }myStruct; How can I convert the structures to a byte stream sent by Server and can be correctly parsed by Client? Any sample code would help! (I heard XML is an option but I am not familiar with it ) Thanks. ...

How many bytes in a JavaScript string?

I have a javascript string which is about 500K when being sent from the server in UTF-8. How can I tell its size in JavaScript? I know that JavaScript uses UCS-2, so does that mean 2 bytes per character. However, does it depend on the JavaScript implementation? Or on the page encoding or maybe content-type? ...

C bits shifting short ints

Hi Why result of include <stdio.h> int main() { unsigned short int i = 0xff ; unsigned short int j; j= i<<2; printf("%x n%x\n", i, j); return 0; } is j = 3fc ? if both i and j are short int - so they are 2bytes values, so j shouldnt =fc ?? thx in advance for explanations. ~ ~ ...

Splitting a Byte array in java

Is it possible to get specific bytes from a byte array in java? I have a byte array: byte[] abc = new byte[512]; and i want to have 3 different byte arrays from this array. byte 0-127 byte 128-255 byte256-511. I tried abc.read(byte[], offset,length) but it works only if I give offset as 0, for any other value it throws an ...

Finding leaks under GeneralBlock-16?

If ObjectAlloc cannot deduce type information for the block, it uses 'GeneralBlock'. Any strategies to get leaks from this block that may eliminate the need of my 'trial and error' methods that I use? The Extended Detail thing doesn't really do it for me as I just keep guessing. ...

convert object(i.e any object like person, employee) to byte[] in silverlight

i have a person object and need to store it as byte[] and again retrieve that byte[] and convert to person object and BinaryFormatter is not availabe in silverlight ...

Size of integers?

This has to do with a question I read yesterday: http://stackoverflow.com/questions/2274428/how-to-determine-how-many-bytes-an-integer-needs Anyway, the part that I have a question about is this: I'm looking for the most efficient way to calculate the minimum number of bytes needed to store an integer without losing precision. ...

Problem with copy byte[] into another byte[]

I have a method to create a hashed password. However it crashes at salt.CopyTo(pwd, 0); Says that the target byte[] is too small. How do I solve the problem? public static byte[] CreateHashedPassword(string password, byte[] salt) { SHA1 sha1 = SHA1.Create(); byte[] pwd = CustomHelpers.StringToByteArray(pa...

2 equal byte[] does not return true

I'm trying to verify someone's password when logging in. I take the entered password and retrieve the users saved hashed password and password salt. Then I hash the entered password with the saved salt to see if it's equal to the saved password. However, even though the byte[] storedPassword is exactly like the byte[] enteredPassword,...

How to locate a sequence of values (specifically, bytes) within a larger collection in .NET.

I need to parse the bytes from a file so that I only take the data after a certain sequence of bytes has been identified. For example, if the sequence is simply 0xFF (one byte), then I can use LINQ on the collection: byte[] allBytes = new byte[] {0x00, 0xFF, 0x01}; var importantBytes = allBytes.SkipWhile(byte b => b != 0xFF); // importa...

Generic BitConverter.GetBytes possible in .NET?

Is it possible to create a method like BitConverter.GetBytes() that accepts as input also a parameter of type Object, without using Marshaling as done here? Or the only solution, if a type Object is given as input, is to implement a case on all available .NET value types? ...

How do I find the number of bytes within UTF-8 string with PHP?

I have the following function from the php.net site to determine the # of bytes in an ASCII and UTF-8 string: <?php /** * Count the number of bytes of a given string. * Input string is expected to be ASCII or UTF-8 encoded. * Warning: the function doesn't return the number of chars * in the string, but the number of bytes. * ...

bytes.Split separator as []byte("...")

In bytes_test.go I see: a := Split([]byte(tt.s), []byte(tt.sep), tt.n) where tt.s and tt.sep are strings. But when I try to do a := bytes.Split([]byte("test"), []byte("e"), 0) I get: cannot convert "test" (type ideal string) to type []uint8 in conversion cannot convert "e" (type ideal string) to type []uint8 in conversion ...

C: Building a byte

I have an array with 16 elements. I would like to evaluate these to a boolean 0 or 1 and then store this in 2 bytes so i can write to a binary file. How do I do this? ...

Difference between byte vs Byte data types in C#

I noticed that in C# there are both a byte and Byte data type. They both say they are of type struct System.Byte and represent an 8-digit unsigned integer. So I am curious as to what the difference if any is between the two, and why you would use one over the other. Thanks! ...

C/C++ packing signed char into int

hello I have need to pack four signed bytes into 32-bit integral type. this is what I came up to: int32_t byte(int8_t c) { return (unsigned char)c; } int pack(char c0, char c1, ...) { return byte(c0) | byte(c1) << 8 | ...; } is this a good solution? Is it portable (not in communication sense)? is there a ready-made solution, perha...

Uploading files to file server...

Using the link below, I wrote a code for my application. I am not able to get it right though, Please refer the link and help me ot with it... http://stackoverflow.com/questions/263518/c-uploading-files-to-file-server The following is my code:- protected void Button1_Click(object sender, EventArgs e) { filePath = FileUpload1.Fi...

Add Hexadecimal Header Info to JPEG File Using Java

I need to add header info to a JPEG file in order to get it to work properly when shared on some websites, I've tracked down the correct info through a lot of Hex digging, but now I'm kind of stuck trying to get it into the file. I know where in the file it needs to go, and I know how long it is, my problem is that RandomAccessFile just...

How are integers casted to bytes in Java?

I know Java doesn't allow unsigned types, so I was wondering how it casts an integer to a byte. Say I have an integer a with a value of 255 and I cast the integer to a byte. Is the value represented in the byte 11111111? In other words, is the value treated more as a signed 8 bit integer, or does it just directly copy the last 8 bits of ...