Hi,
I'm trying to read a file that I have a web address for into a byte array. I've been using File.ReadAllBytes to read files locally and I've been unable to figure out the cleanest way to do this for a file on the web.
I imagine this is just a quick snippet of code, but everything I can find through search is only for local files....
I want to be able to open up an image file and extra the hexadecimal values byte-by-byte. I have no idea how to do this and googling "python byte editing" and "python byte array" didn't come up with anything, surprisingly. Can someone point me towards the library i need to use, specific methods i can google, or tutorials/guides?
...
I'm trying to interact with an application over the network which uses a simple protocol. I have to send a header that looks like this:
2 bytes = Data Length (including Request Type)
1 byte = Request Type
I'm taking both parameters as integers:
private static void WriteHeader(Stream buf, int length, int requestType) {
buf.Write(Bi...
Hi,
What's the fastest way to turn a string into a byte[] array in C#? I'm sending tonnes of string data through sockets and need to optimize every single operation. Currently I transform the strings in to byte[] arrays before sending using:
private static readonly Encoding encoding = new ASCIIEncoding();
//...
byte[] bytes = encodin...
I'm having an issue trying to parse the ascii part of a file, and once I hit the end tag, IMMEDIATELY start reading in the bytes from that point on. Everything I know in Java to read off a line or a whole word creates a buffer, which ruins any chance of getting the bytes immediately following my stop point. Is the only way to do this rea...
In Java, I just read a file into a ByteBuffer. When I started checking to make sure that the ByteBuffer contained the right bytes, I noticed that it had mostly the correct start and end bytes, except for the 3rd byte, it has -117 instead of what emacs says should be 139 (8b in hexl-mode). What gives? Does this have something to do with B...
Could someone explain to me the uses of using buffers, and perhaps some simple (documented) examples of a buffer in use. Thanks.
I lack much knowledge in this area of Java programming, so forgive me if I asked the question wrong. :s
...
Hi to all,
I'm sending to a device a request as byte array and I want to receive the anwser device gives.
...
Socket deviceSocket = new Socket(server);
List<byte> coming = new List<byte>();
...
deviceSocket.Receive(coming)
Here the program gives error:
Error 1
The best overloaded method match for 'System.Net.Sockets.Socket.Recei...
This is what I've come up with so far, but it doesn't seem very optimal, any ideas on better approaches?
public void ToBytes(object[] data, byte[] buffer)
{
byte[] obytes;
int offset = 0;
foreach (object obj in data)
{
if (obj is string)
obytes = System.Text.Encoding.UTF8.GetBytes(((string)obj));
...
I'm looking at the C# library called BitStream, which allows you to write and read any number of bits to a standard C# Stream object. I noticed what seemed to me a strange design decision:
When adding bits to an empty byte, the bits are added to the MSB of the byte. For example:
var s = new BitStream();
s.Write(true);
Debug.Assert(s.To...
Hello :)
I have a byte array similar to this (16 bytes):
71 77 65 72 74 79 00 00 00 00 00 00 00 00 00 00
I use this to convert it to a string and trim the ending spaces:
ASCIIEncoding.ASCII.GetString(data).Trim();
I get the string fine, however it still has all the ending spaces.
So I get something like "qwerty.........." (where d...
When reading data over the network, you specify a buffer to receive the data into:
byte[] b = new byte[4096];
socket.Receive(b);
Now my first thought is of course to reuse the receive buffer by declaring it as a member variable of the class. My next issue is that I have not received all of the data that I am expecting, so I need to bu...
Below is code I copied (from this site) and modified only slightly since the original code would not compile. I want to manipulate the byte array for edge detection and eventually simple changes to colors, but first I wanted to get the basic code working. Currently, the system compiles and runs. It displays a badly drawn elephant on scre...
Could somebody tell me how can I convert byte[] to ArrayList by using C# under Windows Mobile?
Later edit:
this would go like having an ArrayList containing instances of a custom type. This list goes to a database (into a blob) as a byte array (the conversion is done by the database API); What I want is to revert the byte[] to ArrayL...
Could someone please give me an example on how can I convert a byte[] to an ArrayList of Hashtables with C# ? (the byte[] represents the ArrayList of Hashtables that was previously serialized)
Note: I'm running under Windows Mobile, which does not provide BinaryFormatter.
...
I need to take pairs of bytes in, and output shorts, and take shorts in and output pairs of bytes. Here are the functions i've devised for such a purpose:
static short ToShort(short byte1, short byte2)
{
short number = (short)byte2;
number <<= 4;
number += (short)byte1;
return number;
}
static void FromShort(short number...
Hi there,
I want to convert bytes to GB.
value= 8587321344
So it should be 8587321344/1024/1024/1024
But whenever I go to divide, the value is wrong...
If I cast it into integer, it will be limited to 2147....
Can't find any type cast to long data type...
Funny enough...
How to perform this calculation to show correct output...
Th...
In Java,
How could the bytes sent and received over an active HTTP connection be counted?
I want to display some statistics like:
Bytes Sent : xxxx Kb
Bytes Received : xxxx Kb
Duration : hh:mm
...
Let's say I have the string "1e". In Java, how can I convert it to the byte 0x1e?
...
I am comparing to files by reading it into filestream and comparing byte by byte..now how can i skip whitespaces while comparing?I am using C#.net
...