short

Is wchar_t just a typedef of unsigned short?

荒凉一梦 提交于 2019-12-18 07:29:33
问题 for example, does: wchar_t x; translate to: unsigned short x; 回答1: In short: in C may be in C++ no. Widely. C defines wchar_t as typedef but in Unix it is generally 4 bytes (so generally not short) and in Windows 2 so it may be short. Under C++ it is unique built-in type like char or int , so you can legally overload void foo(short x) and void foo(wchar_t x) 回答2: For anyone else who may come across this answer because function calls in your Visual Studio project won't link, despite both

C#: Array of references / pointers to a number of integers

与世无争的帅哥 提交于 2019-12-18 06:57:37
问题 I would like to hold references to a number of shorts in an array. I assumed I could just create the shorts and then add them to the array. So... every time the referenced object is changed, this is reflected in the array, and vice versa. Doing some trials convinced me that it does not quite work that way. In fact, it looks like the value is transferred but not a reference. Below code creates two shorts, adds these to an array as objects, then changes the original short. However, when

bitwise-ANDing with 0xff is important?

 ̄綄美尐妖づ 提交于 2019-12-17 23:39:39
问题 Doesn't bitwise-ANDing with 0xff essentially mean getting the same value back, for that matter, in this code? byte[] packet = reader.readPacket(); short sh; sh = packet[1]; sh &= 0xFF; System.out.print(sh+" "); Weirdly, I get a -1 if that ANDing is not included but a 255 when included Could someone explain the reason? As I see it 0xff is just 1111 1111. Isn't it? 回答1: Yes, 0xff is just 1111 1111 . But this is attempting to display the unsigned byte value, even though in Java byte s are signed

What happens when you cast from short to byte in C#?

拈花ヽ惹草 提交于 2019-12-17 21:29:25
问题 I have the following code: short myShort = 23948; byte myByte = (byte)myShort; Now I wasn't expecting myByte to contain the value 23948. I would have guessed that it would contain 255 (I believe the largest value for a byte). However, it contains 140, and it made me wonder why; what is actually going on behind the scenes? Please note that I am not looking for someone to solve the problem that 23948 cannot fit into a byte, I am merely wondering about the underlying implementation 回答1: Short is

C# Short Error: Negating the minimum value of a twos complement number is invalid

爱⌒轻易说出口 提交于 2019-12-17 21:02:25
问题 I have been encountering this error for my project, which involves working with Digital Audio Signals. So I have been getting the amplitude values and recently encountered this error. This occurs when the amplitude value encountered is "-32768" upon debugging. I am storing the values in a short[] array. I have a hunch that it has something to do with max/minimum values (I use Math.Abs) but I am unsure on how to handle it. Can someone help? Thanks! 回答1: 16 bit signed int ( short ) takes values

Converting 2 bytes to Short in C#

懵懂的女人 提交于 2019-12-17 16:43:13
问题 I'm trying to convert two bytes into an unsigned short so I can retrieve the actual server port value. I'm basing it off from this protocol specification under Reply Format. I tried using BitConverter.ToUint16() for this, but the problem is, it doesn't seem to throw the expected value. See below for a sample implementation: int bytesRead = 0; while (bytesRead < ms.Length) { int first = ms.ReadByte() & 0xFF; int second = ms.ReadByte() & 0xFF; int third = ms.ReadByte() & 0xFF; int fourth = ms

Really simple short string compression

China☆狼群 提交于 2019-12-17 09:46:33
问题 Is there a really simple compression technique for strings up to about 255 characters in length (yes, I'm compressing URLs)? I am not concerned with the strength of compression - I am looking for something that performs very well and is quick to implement. I would like something simpler than SharpZipLib: something that can be implemented with a couple of short methods. 回答1: I think the key question here is " Why do you want to compress URLs? " Trying to shorten long urls for the address bar?

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

What is short circuiting and how is it used when programming in Java? [duplicate]

半世苍凉 提交于 2019-12-17 02:23:24
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Does java evaluate remaining conditions after boolean result is known Why do we usually use || not |, what is the difference? I missed my class lecture the other day and I was wondering if anyone could give an explanation what short circuiting is and maybe an example of it being used in a simple Java program. Thanks for your help! 回答1: Short-circuiting is where an expression is stopped being evaluated as soon as

Weird Result Incrementing a Short Beyond its Maximum Value

和自甴很熟 提交于 2019-12-14 01:28:36
问题 When i execute this code it gives value of s as -7616. Why so? Is this because loss of data while converting it to short from int or something else? public static void main(String[] args) { // TODO code application logic here short s=0; int x=123456; int i=8; s +=x; System.out.println(s); } 回答1: Good question! It made me think about things I haven't thought about in a long while and I had to brush up on a couple of concepts. Thanks for helping me knock the rust off my brain. For me this type