-2

I need to divide by 2 the short word, for example 0x40 (in dec: 64 ) to 0x20 (in dec: 32). I cannot use int (java card) - only short.

Someone have any idea?

luk2302
  • 55,258
  • 23
  • 97
  • 137
Thulion
  • 97
  • 1
  • 11

2 Answers2

3

How about...

short myShort = (short) 0x40;
myShort >>= 1;

Where the shift right operator is used to perform integer division by 2.

vojta
  • 5,591
  • 2
  • 24
  • 64
Kayaman
  • 72,141
  • 5
  • 83
  • 121
0

If all you want to do is divide a short by 2 then I'd use a bit shift operator. as in

    short a = 8;
    a >>= 1;                  // Shift by one bit is the same as divide by 2
    System.out.println(a);
Stormcloud
  • 2,065
  • 2
  • 21
  • 41