byte

Actionscript 3 , generating random numbers and placing in byte array, faster?

别等时光非礼了梦想. 提交于 2019-12-11 06:13:55
问题 I am trying to generate large byte arrays of random bytes. Using the below code I can generate 10 million random bytes and place in a byte array in about 4 seconds. 2 seconds for the generation and 2 second to place on the array. for (var i:Number = 0; i < reqLength; i++){ rnd = Math.random() * 255; randomBytes.writeByte(rnd); } Does a faster way exist? I am generating int s because I am creating a byte array of extended ASCII chars. 回答1: With a few tweaks I tuned it down from 4s to 0.5s. var

How can I store a byte[] list in viewstate?

删除回忆录丶 提交于 2019-12-11 05:26:16
问题 I want to store some byte[] to ViewState. For example I want to store a list of FileBytes. How can I do it? 回答1: I haven't actually tried this with a list, but it should be pretty simple: List<byte> myByteList; // do something here to load list ViewState["Bytes"] = myByteList When you need to get it out: List<byte> myByteList = (List<byte>)ViewState["Bytes"]; Edit: Changed from byte[] to List. 来源: https://stackoverflow.com/questions/4915206/how-can-i-store-a-byte-list-in-viewstate

How to specify end of file when sending it over network

白昼怎懂夜的黑 提交于 2019-12-11 05:16:11
问题 My servlet reads from a binary file using the FileInputStream.read(). This returns -1 if end of file is reached. It then sends the bytes of the file to the client over the response stream. I want to then send the bytes of a md5 hash of the file over the response stream. How should i split the end of file from the md5 of the file so that the client knows which bytes are which? I can't send a -1 byte because then the stream stops working. Are there any other bytes i can send to signal end of

Size of byte (clarification)

a 夏天 提交于 2019-12-11 05:08:23
问题 I'm writing a game server, and this might be an easy question, but I just want some clarification. Why is it that a byte (char or unsigned char) can hold up to a value of 255 (0xFF, which I believe is 2 bytes)? When I use sizeof(unsigned char) the compiler tells me it is 1 byte. Is it because (in ACSII) it is getting "converted" to a character? Sorry for this poor explaination, I'm not really good at describing a question. 回答1: This touches on a bunch of subjects, including the historical

Convert inputText to byte[] in JSF

非 Y 不嫁゛ 提交于 2019-12-11 05:08:10
问题 I'm writing a web application which has a JSF page with a bean behind it. I am having trouble with it and I think it's because the bean is expecting a byte array for one particular field and it's being provided with a String. From what I understand, JSF provides some functionality to automatically convert whatever you enter in your inputText fields to the required data type, but I don't think it does this when you want a byte[] ... Is it simply a matter of writing a customer converter for JSF

byte, char, int in Java - bit representation

偶尔善良 提交于 2019-12-11 04:39:03
问题 I am confused with byte and char in Java. I have the following program segment : byte b = 65; char c = 65; short s = 65; System.out.println("b:"+b+" c:"+c+ " s:"+s); // outputs b:65 c:A s:65 The bit representation of b, c and s are same they all are :: 00000000 01000001 . My question is if the bits are same then how they act differently - b as byte, c as char and s as short ? Another question is : char c = 65; why this is a correct statement ? it does not give error though I am assigning int

Getting metadata from JPEG in byte array form

﹥>﹥吖頭↗ 提交于 2019-12-11 04:19:32
问题 I have a jpeg image in the form of a byte array. How can I get the byte array in a form where I can strip the comments node of the metadata? byte[] myimagedata = ... ImageWriter writer = ImageIO.getImageWritersBySuffix("jpeg").next(); ImageReader reader = ImageIO.getImageReader(writer); //Looking for file here but have byte array reader.setInput(new FileImageInputStream(new File(Byte array cant go here))); IIOMetadata imageMetadata = reader.getImageMetadata(0); Element tree = (Element)

How to initialiaze a unsigned byte array with a set of well known values in Java 7?

只谈情不闲聊 提交于 2019-12-11 04:19:09
问题 I want to initialize a byte array with unsigned byte values ranging from 0 to 255. Here is how I did it: int N = 256; char[] tmp = new char[N]; for (char c = 0; c < N; c++) { tmp[c] = c; } byte[] table = new byte[N]; table = Charset.forName("US-ASCII").encode(CharBuffer.wrap(tmp)).array(); int i=1; for(byte b : table) { System.out.format("%02X ", b); if(i%10==0) { System.out.println(); } i++; } This produces: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B

What is PHP for C# ReadBytes(stream langth)?

眉间皱痕 提交于 2019-12-11 04:14:21
问题 What is PHP for C# (asuming we open some local (on server) file instead of OpenFileDialog private const int HEADER_LENGTH = 13; stream = File.OpenRead(openFileDialog.FileName); header = ReadBytes(stream, HEADER_LENGTH); And will we be able to do something like this in PHP as a next step private const byte SIGNATURE1 = 0x46; private const byte SIGNATURE2 = 0x4C; private const byte SIGNATURE3 = 0x56; if ((SIGNATURE1 != header[0]) || (SIGNATURE2 != header[1]) || (SIGNATURE3 != header[2])) throw

Convert array of 8 bytes to signed long in C++

独自空忆成欢 提交于 2019-12-11 04:06:32
问题 I have an array of 8 bytes and I'm trying to convert it to a signed long in C++, and can't seem to figure it out. From what I could tell long ints are only 4 bytes, can anybody provide some information on this? Is it going to matter if it is 32 or 64 bit? 回答1: You probably should use a int64_t which is guaranteeed to be 8 bytes long. You don't state how your data is represented (its endianness) into your array but you might use reinterpret_cast<> or even better: use shift operations to "build