byte

C# Append byte array to existing file

╄→гoц情女王★ 提交于 2019-12-17 07:27:50
问题 I would like to append a byte array to an already existing file (C:\test.exe) . Assume the following byte array: byte[] appendMe = new byte[ 1000 ] ; File.AppendAllBytes(@"C:\test.exe", appendMe); // Something like this - Yes, I know this method does not really exist. I would do this using File.WriteAllBytes, but I am going to be using an ENORMOUS byte array, and System.MemoryOverload exception is constantly being thrown. So, I will most likely have to split the large array up into pieces and

How do you specify a byte literal in Java?

ε祈祈猫儿з 提交于 2019-12-17 05:40:55
问题 If I have a method void f(byte b); how can I call it with a numeric argument without casting? f(0); gives an error. 回答1: You cannot. A basic numeric constant is considered an integer (or long if followed by a "L"), so you must explicitly downcast it to a byte to pass it as a parameter. As far as I know there is no shortcut. 回答2: You have to cast, I'm afraid: f((byte)0); I believe that will perform the appropriate conversion at compile -time instead of execution time, so it's not actually

byte array to short array and back again in java

馋奶兔 提交于 2019-12-17 04:26:31
问题 I'm having some issues taking audio data stored in a byte array, converting it to a big-endian short array, encoding it, then changing it back into a byte array. Here is what I have. The original audio data is stored in audioBytes2. I am using the same format for decode with a minus on the cos function instead. Unfortunately, changing the byte and short data types is non-negotiable. short[] audioData = null; int nlengthInSamples = audioBytes2.length / 2; audioData = new short[nlengthInSamples

How to convert a byte to its binary string representation

微笑、不失礼 提交于 2019-12-17 04:12:31
问题 For example, the bits in a byte B are 10000010 , how can I assign the bits to the string str literally, that is, str = "10000010" . Edit I read the byte from a binary file, and stored in the byte array B . I use System.out.println(Integer.toBinaryString(B[i])) . the problem is (a) when the bits begin with (leftmost) 1, the output is not correct because it converts B[i] to a negative int value. (b) if the bits begin with 0 , the output ignore 0 , for example, assume B[0] has 00000001, the

Does .NET provide an easy way convert bytes to KB, MB, GB, etc.?

久未见 提交于 2019-12-17 03:50:43
问题 Just wondering if .NET provides a clean way to do this: int64 x = 1000000; string y = null; if (x / 1024 == 0) { y = x + " bytes"; } else if (x / (1024 * 1024) == 0) { y = string.Format("{0:n1} KB", x / 1024f); } etc... 回答1: Here is a fairly concise way to do this: static readonly string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" }; static string SizeSuffix(Int64 value, int decimalPlaces = 1) { if (decimalPlaces < 0) { throw new ArgumentOutOfRangeException(

Convert any object to a byte[]

£可爱£侵袭症+ 提交于 2019-12-17 02:05:17
问题 I am writing a prototype TCP connection and I am having some trouble homogenizing the data to be sent. At the moment, I am sending nothing but strings, but in the future we want to be able to send any object. The code is quite simple at the moment, because I thought everything could be cast into a byte array: void SendData(object headerObject, object bodyObject) { byte[] header = (byte[])headerObject; //strings at runtime, byte[] body = (byte[])bodyObject; //invalid cast exception // Unable

What is the difference between a string and a byte string?

假装没事ソ 提交于 2019-12-16 22:35:09
问题 I am working with a library which returns a byte string and I need to convert this to a string. Although I'm not sure what the difference is - if any. 回答1: Assuming Python 3 (in Python 2, this difference is a little less well-defined) - a string is a sequence of characters, ie unicode codepoints; these are an abstract concept, and can't be directly stored on disk. A byte string is a sequence of, unsurprisingly, bytes - things that can be stored on disk. The mapping between them is an encoding

objective c 不同数据类型转换

…衆ロ難τιáo~ 提交于 2019-12-15 18:59:10
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> NSString 转 byte字节 NSData *strDataBytes = [ @"$$" dataUsingEncoding : NSUTF8StringEncoding ]; 转换结果为{0x24, 0x24}; int 转 byte NSMutableData *myData = [[ NSMutableData alloc ] init ]; int num = 1024; [myData appendBytes:& num length:sizeof( num )]; Byte数组 转 NSData Byte *bytes = {***}; NSData *strData = [ NSData dataWithBytes :bytes length :strlen]; NSData 转 NSString NSData *strData = ***; NSString * string = [[ NSString alloc ] initWithData :strData encoding : NSUTF8StringEncoding ]; 来源: oschina 链接: https://my.oschina.net/u/1402271/blog/277844

Java - indexing into array with a byte

这一生的挚爱 提交于 2019-12-14 04:00:42
问题 Is it possible to index a Java array based on a byte? i.e. something like array[byte b] = x; I have a very performance-critical application which reads b (in the code above) from a file, and I don't want the overhead of converting this to an int. What is the best way to achieve this? Is there a performance-decrease as a result of using this method of indexing rather than an int? With many thanks, Froskoy. 回答1: There's no overhead for "converting this to an int." At the Java bytecode level,

Byte Vigenere Cipher, error with decryption

喜欢而已 提交于 2019-12-14 03:54:14
问题 I have to write a Vigenere encryption / decryption function that operates on full bytes (to encrypt and send files over tcp and then decrypt on the other side). My encrypting function seems to be working (more or less, can't really test it without decrypting function). This is the code of the encrypting function: public static Byte[] encryptByteVigenere(Byte[] plaintext, string key) { Byte[] result= new Byte[plaintext.Length]; key = key.Trim().ToUpper(); int keyIndex = 0; int keylength = key