byte

reading bytes in a file in vb.net

…衆ロ難τιáo~ 提交于 2019-12-12 14:29:43
问题 After getting the file name I create a new filestream and load all the bytes from the FileStream into a byte array, now I need to get certain bytes and store them in fields like the second 4 bytes are the time the file was created. When storing these in the variables should I store them as bytes or as string/integers/etc. Or have I done it completely wrong? EDIT:Should I be doing this way instead of a filestream? Dim data() as Byte = File.ReadAllBytes(path1) 回答1: Using File.ReadAllBytes is a

Converting US-ASCII encoded byte to integer and back

亡梦爱人 提交于 2019-12-12 14:14:30
问题 I have a byte array that can be of size 2,3 or 4. I need to convert this to the correct integer value. I also need to do this in reverse, i.e an 2,3 or 4 character integer to a byte array. e.g., raw hex bytes are : 54 and 49. The decoded string US-ASCII value is 61. So the integer answer needs to be 61. I have read all the conversion questions on stackoverflow etc that I could find, but they all give the completely wrong answer, I dont know whether it could be the encoding? If I do new String

how many color combinations in a 24 bit image

本秂侑毒 提交于 2019-12-12 13:07:43
问题 I am reading a book and I am not sure if its a mistake or I am misunderstanding the quote. It reads... Nowadays every PC you can buy has hardware that can render images with at least 16.7 million individual colors. Rather than have an array with thousands of color entries, the images instead contain explicit color values for each pixel. A 24-bit display, of course, uses 24 bits, or 3 bytes per pixel, for color information. This gives 1 byte, or 256 distinct values each, for red, green, and

Convert Byte[] to int

久未见 提交于 2019-12-12 12:43:53
问题 I have this method that converts a signed or non-signed byte to int , but it doesn't return what it is supposed to return. Can someone point out the issue in the below code? public int convertByteToInt(byte[] b){ int value= 0; for(int i=0;i<b.length;i++){ int n=(b[i]<0?(int)b[i]+256:(int)b[i])<<(8*i); value+=n; } return value; } Edited : I'am actualy reading a wav file in order to calculate the SNR. the returned value from the conversion should give something beetween 0 and 255. The

Why is the smallest value that can be stored is a Byte(8bit) & not a Bit(1bit)?

老子叫甜甜 提交于 2019-12-12 12:31:02
问题 Why is the smallest value that can be stored a Byte(8bit) & not a Bit(1bit) in memory? Even booleans are stored as Bytes. Will we ever bump the smallest number to 32 or 64bits like register's on the CPU? 回答1: The underlying methods of processor access are limited to the size of the smallest usable register. On most architectures, that size is 8 bits. You can use smaller portions of these; for instance, C has the bitfield feature in structs that will allow combining fields that only need to be

DotNetZip: Convert ZipFile to byte[] array

余生长醉 提交于 2019-12-12 11:27:58
问题 I'm using DotNetZip to add a file to a zip archive, which I've read from the file system. I'd like to convert the resulting ZipFile to byte[] array. Any assistance will be highly appreciated. My code is shown below. public byte[] AddPrjFile(FileStream shapeFileZip, Uri prjLocation) { string prjFileAbsPath = prjLocation.AbsolutePath; using (ZipFile zip = ZipFile.Read(shapFileZip)) { ZipEntry e = zip.AddFile(prjFileAbsPath); e.FileName = zipFile.Name + ".prj"; } return byte_array; } 回答1: You

signed byte type and bitwise operators in Java?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 11:03:47
问题 quoting from oracle website "byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive)". here, the first two lines are valid but the last is not byte b = -128; byte b1 = 127; byte b2 = b>>>b1;//illegal Q1) what is meant exactly by 8-bit signed? 128 in binary format would be 1000 0000 and -128 would need an extra bit for the negative sign, where it would fit if all the 8 bits are occupied. Q2) for int, there is a

How would I take the first “n” elements of a byte array and convert them directly into a string?

不想你离开。 提交于 2019-12-12 10:58:32
问题 I have an array of bytes consisting of 1024 elements. I want to break this down into different string private members (e.g. first 9 bytes for name, next 12 bytes for userID, etc.). Without having to turn the entire byte array into a string and then using a substring method, is there any way I can turn a range of bytes in the array directly into a private member for my class? E.g. myObject.name = byteArr[0-9]; myObject.userId = byteArr[10-21]; 回答1: Use: String myField = new String(myArray,

How to implement C# enum for enumerated char(1) database field?

[亡魂溺海] 提交于 2019-12-12 10:49:52
问题 OK, so I have a database field of type char(1) that has a small number of possible state codes (e.g. 'F'= Failure, 'U'=Unknown, etc.). I'd like to have a C# enum class that corresponds to these states. I can do: public enum StatusCode : byte { Unknown = (byte) 'U', Failure = (byte) 'F', // etc. } So far so good. But in the DataTable returned from the database, the column values are System.Data.SqlTypes.SqlString instances. There are obviously some issues converting from a C# string (or even a

How many characters does bin2hex(random_bytes()) depending on input?

a 夏天 提交于 2019-12-12 10:45:07
问题 I'm using the following code to genrate a simple UID for my app: private function _createUid() { $bytes = random_bytes(128); $uid = bin2hex($bytes); return $uid; } By doing this, the result of _createUid() will be a 256 character string. My question is, will this string always be 256 characters if run on the same server, I'm aware of some differences on different servers. Also, is one byte equal to two characters? Any help would be great, thanks! 回答1: In hex a byte is always expressed as 2