byte

get bytes from array function vb.net

I need to get the bytes from an array of bytes starting at a certain index and for a certain length (4), how can get this? Note: I don't want to use the Array.copy sub as it is not a function. I need to put it in something like Sub MySub([arguement as byte()]the_function_I_Need(Array, index, length)) ...

convert a single into 8 bytes invb.net

I have a single that might have a decimal place but might not. I have to put the digit before the decimal into the first 4 bytes and the digit after in the next 4 bytes. So 1.1 would be 01-00-00-00-01-00-00-00 or 2.1 would be 02-00-00-00-01-00-00-00 or 1 would be 01-00-00-00-00-00-00-00 The digit before the decimal point is stored like ...

how to extract specific bytes from a file using unix

how do I extract 12byte chunks from a binary file at certain positions within the file. If I wanted to extract the first 12 bytes I could do something like head -c12 file.bin>output If I wanted to extract 12 bytes from byte61 I could do something like head -c72 file.bin|tail -c12 >output Is there a simpler way if I have something ...

get length of data sent over network to TCPlistener/networkstream vb.net

It seems the most obvious thing, but I just can't work out how to get the length of bytes sent over a network using a TCPClient and TCPListener? This is my code so far: 'Must listen on correct port- must be same as port client wants to connect on. Const portNumber As Integer = 9999 Dim tcpListener As New TcpListener(IPAddress...

System.IO.UnmanagedMemoryStream - why Byte* instead of IntPtr

Anybody have any idea why the BCL team chose to use Byte* instead of IntPtr in the constructors for UnmanagedMemoryStream? This forces you into using an unsafe context in order to construct the type. It seems like they could have used IntPtr and that wouldn't have forced the unsafe context. ...

Determine color quality of image byte stream in sql

Does anyone know of a way to determine if a image stream is in color or black and white, I have thousands of images to process from sql server stored in a varbinary. Can one read the images header (if type of image is known - bitmaps) from byte offsets directly? IF so how can i do this in sql. ...

Converting a set of strings to a byte[] array

Hello, I am tring to convert a set of strings to a byte[] array. At first, I do something like this to convert a byte array to a string: public String convertByte(byte[] msg) { String str = ""; for(int i = 0; i < msg.length; i++) { str += (msg[i] + " * "); } return str; } When I try to convert b...

Image format and unsigned char arrays

I'm developping imaging functions (yes I REALLY want to reinvent the wheel for various reasons). I'm copying bitmaps into unsigned char arrays but I'm having some problem with byte size versus image pixel format. for example a lot of images come as 24 bits per pixel for RGB representation so that's rather easy, every pixel has 3 unsign...

Adding a numerical value to a byte?

public void EncryptFile() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|All files (*.*)|*.*"; dialog.InitialDirectory = @"C:\"; dialog.Title = "Please select an image file to encrypt."; if (dialog.ShowDialog() == ...

Lambda expression compilation

Hi! Given the lambda expression below where Province type contains a public property "byte CountryId" and Country type which contains a public property "byte Id". Expression<Func<Province, bool>> exp = p => p.CountryId == country.Id; The Expression is later used by NHibernate Linq provider and threw an exception. When I inspected th...

Is there a way to know if Emacs is actuall using a byte ocompiled file (.elc)?

Is there a way to know if Emacs is actually using a byte compiled file (.elc)? It is necessary to put all .elc files i a folder or just in the same directory has their original .el? ...

pass by reference without the ref keyword

I'm not a veteran in socket programming, so while analyzing code I found in a database API I came across this code public static void WriteInt(int i, NetworkStream bufOutputStream) { byte[] buffer = new byte[IntSize]; WriteInt(i, buffer, 0); bufOutputStream.Write(buffer, 0, buffer.Length); } pu...

sum of bytes with unsigned long overflow in python

how to translate this piece of C code into Python >=2.6 ? unsigned long memSum(unsigned char *p, unsigned long len) { unsigned long i, sum=0; for(i=0; i<len; i++) sum = sum + *p++; return sum; } of course f=open("file_to_sum",'rb') m = f.read() f.close() sum( array.array('B', m) ) does not work ...

convert from int to byte

Hello, I got the error: System.ArgumentException: Object must be of type Int32. in this code: MyBO target = new MyBO() { x1 = 20 }; In MyBO i have an attribute: public byte x1 {get; set;} What's wrong? I tried with MyBO target = new MyBO() { x1 = (byte)20 }; but i got the same error. Please help. Thanks! ...

How can I add and remove bytes on from the start of a file?

I'm trying to open an existent file save a bytes in the start of it to later read them. How can I do that? Because the "&" operand isn't working fo this type of data. I'm using Encoding.UTF8.GetBytes("text") to convert info to bytes and then add them. Help Please. ...

C# byte[] comparison without bound checks

I am looking for performance efficient ways to compare two byte[] for equality. Sizes are above 1 MB, so the overhead for each array element should be minimized. I aim to beat the speeds of SequenceEqual or a hand-coded for-loop over every item, by avoiding the repetitive bound checks for both arrays. In the same way that Array.Copy co...

Java integer to byte array

I got an integer: 1695609641 when I use method: String hex = Integer.toHexString(1695609641); system.out.println(hex); gives: 6510f329 but I want a byte array: byte[] bytearray = new byte[] { (byte) 0x65, (byte)0x10, (byte)0xf3, (byte)0x29}; how can i make this?? :D thnx! ...

Java: InputStream read() returns a byte bigger than 127?

Hi, I've this code: InputStream is = socket.getInputStream(); int b; while ((b = is.read()) != -1) { System.out.println(b); } A byte its range is -128 until +127. But one of the printed bytes is 210. Is this the result of converting the read byte to an int? (So that the negatif byte becomes a positif int) If so, can I do the same...

Convert short to byte[] in Java

How can I convert a short (2 bytes) to a byte array in Java, e.g. short x = 233; byte[] ret = new byte[2]; ... it should be something like this. But not sure. ((0xFF << 8) & x) >> 0; EDIT: Also you can use: java.nio.ByteOrder.nativeOrder(); To discover to get whether the native bit order is big or small. In addition the follow...

binary coded decimals (BCD) put into a byte in C#

Hi I'm working on implementing a protocol tha tells me to put decimals from 0 to 160 into a single byte. I assume, since it doesn't specify what sort of BCD it wants, that I am to put one digit into the lower nibble and the other decimal into the higher nibble. Meaning I get 1 byte with a two-digit decimal. But how would any larger value...