Questions tagged [short]

A short integer is an integer number which may take less storage, while having a smaller range, than a standard integer on the same machine.

A short integer is an integer number which may take less storage, while having a smaller range, than a standard integer on the same machine.

It is represented by the keyword short in several programming languages.

In , it is required to be at least 16 bits.

In , short (or Short in ) is an alias of System.Int16.


See also:

629 questions
115
votes
7 answers

Java's L number (long) specification

It appears that when you type in a number in Java, the compiler automatically reads it as an integer, which is why when you type in (long) 6000000000 (not in integer's range) it will complain that 6000000000 is not an integer. To correct this, I…
jbu
  • 15,831
  • 29
  • 82
  • 105
103
votes
3 answers

Why is "short thirty = 3 * 10" a legal assignment?

If short is automatically promoted to int in arithmetic operations, then why is: short thirty = 10 * 3; A legal assignment to the short variable thirty? In turn, this: short ten = 10; short three = 3; short thirty = ten * three; // DOES NOT COMPILE…
Ceiling Gecko
  • 3,104
  • 2
  • 24
  • 33
81
votes
4 answers

Why must a short be converted to an int before arithmetic operations in C and C++?

From the answers I got from this question, it appears that C++ inherited this requirement for conversion of short into int when performing arithmetic operations from C. May I pick your brains as to why this was introduced in C in the first place?…
dayuloli
  • 16,205
  • 16
  • 71
  • 126
79
votes
11 answers

Primitive type 'short' - casting in Java

I have a question about the primitive type short in Java. I am using JDK 1.6. If I have the following: short a = 2; short b = 3; short c = a + b; the compiler does not want to compile - it says that it "cannot convert from int to short" and…
user42155
  • 48,965
  • 27
  • 59
  • 60
75
votes
5 answers

Integer summing blues, short += short problem

Program in C#: short a, b; a = 10; b = 10; a = a + b; // Error : Cannot implicitly convert type 'int' to 'short'. // we can also write this code by using Arithmetic Assignment Operator as given below a += b; // But this is running successfully,…
71
votes
16 answers

Unsigned short in Java

How can I declare an unsigned short value in Java?
maiky
  • 3,503
  • 7
  • 28
  • 28
56
votes
10 answers

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…
Hugh
  • 1,182
  • 2
  • 9
  • 14
54
votes
6 answers

byte array to short array and back again in java

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…
Aaron
  • 541
  • 1
  • 4
  • 3
52
votes
9 answers

Cannot implicitly convert type 'int' to 'short'

I wrote the following small program to print out the Fibonacci sequence: static void Main(string[] args) { Console.Write("Please give a value for n:"); Int16 n = Int16.Parse(Console.ReadLine()); Int16 firstNo = 0; Int16 secondNo =…
m.edmondson
  • 30,382
  • 27
  • 123
  • 206
52
votes
7 answers

php: number only hash?

In php is there a way to give a unique hash from a string, but that the hash was made up from numbers only? example: return md5(234); // returns 098f6bcd4621d373cade4e832627b4f6 but I need return numhash(234); // returns 00978902923102372190 (20…
Timo Huovinen
  • 53,325
  • 33
  • 152
  • 143
51
votes
4 answers

When to use `short` over `int`?

There are many questions that asks for difference between the short and int integer types in C++, but practically, when do you choose short over int?
dayuloli
  • 16,205
  • 16
  • 71
  • 126
51
votes
3 answers

Ternary operator behaviour inconsistency

Following expression is ok short d = ("obj" == "obj" ) ? 1 : 2; But when you use it like below, syntax error occurs short d = (DateTime.Now == DateTime.Now) ? 1 : 2; Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists…
Mehmet Kasalak
  • 457
  • 4
  • 13
37
votes
5 answers

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

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…
user1214845
36
votes
6 answers

2 bytes to short

I'm reading a packet with a length of 133 bytes from the serialport, the last 2 bytes contain the CRC values, 2 byte values I've made single (short I think) using Java. This what I have done: short high = (-48 & 0x00ff); short low = 80; short c =…
Nilesh
33
votes
4 answers

What is the value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT?

I am printing Toast message in my application to show notification but i want to know value of Toast.LENGTH_LONG and Toast.LENGTH_SHORT. What other values i can use. Can anyone tell me what is the value of these two variables?
CoDe
  • 11,056
  • 14
  • 90
  • 197
1
2 3
41 42