Use the post increment operator '++'
to INCREASE the value of a numeric type
variable/field by 1
. An extra implicit cast is necessary to return the
promoted numeric type value to the original numeric type value of the
variable/field for the following types: byte
, short
, and char
. If a
variable/field is read as part of an expression the value is loaded prior to the
increment.
Errors
-
If the variable/field is a non-numeric type.
Grammar
post_increment: ( variable | field ) '++';
Promotion
original | promoted | implicit |
---|---|---|
byte |
int |
byte |
short |
int |
short |
char |
int |
char |
int |
int |
|
long |
long |
|
float |
float |
|
double |
double |
|
def |
def |
Examples
-
Post increment with different numeric types.
short i = 0; (1) i++; (2) long j = 1; (3) long k; (4) k = j++; (5)
-
declare
short i
; storeshort 0
toi
-
load from
i
→short 0
; promoteshort 0
: resultint
; addint 0
andint 1
→int 1
; implicit castint 1
toshort 1
; storeshort 1
toi
-
declare
long j
; implicit castint 1
tolong 1
→long 1
; storelong 1
toj
-
declare
long k
; store defaultlong 0
tok
-
load from
j
→long 1
; storelong 1
tok
; addlong 1
andlong 1
→long 2
; storelong 2
toj
-
-
Post increment with the
def
type.def x = 1; (1) x++; (2)
-
declare
def x
; implicit castint 1
todef
→def
; storedef
tox
-
load from
x
→def
; implicit castdef
toint 1
; addint 1
andint 1
→int 2
; implicit castint 2
todef
; storedef
tox
-
Use the post decrement operator '--'
to DECREASE the value of a numeric type
variable/field by 1
. An extra implicit cast is necessary to return the
promoted numeric type value to the original numeric type value of the
variable/field for the following types: byte
, short
, and char
. If a
variable/field is read as part of an expression the value is loaded prior to
the decrement.
Errors
-
If the variable/field is a non-numeric type.
Grammar
post_decrement: ( variable | field ) '--';
Promotion
original | promoted | implicit |
---|---|---|
byte |
int |
byte |
short |
int |
short |
char |
int |
char |
int |
int |
|
long |
long |
|
float |
float |
|
double |
double |
|
def |
def |
Examples
-
Post decrement with different numeric types.
short i = 0; (1) i--; (2) long j = 1; (3) long k; (4) k = j--; (5)
-
declare
short i
; storeshort 0
toi
-
load from
i
→short 0
; promoteshort 0
: resultint
; subtractint 1
fromint 0
→int -1
; implicit castint -1
toshort -1
; storeshort -1
toi
-
declare
long j
; implicit castint 1
tolong 1
→long 1
; storelong 1
toj
-
declare
long k
; store defaultlong 0
tok
-
load from
j
→long 1
; storelong 1
tok
; subtractlong 1
fromlong 1
→long 0
; storelong 0
toj
-
-
Post decrement with the
def
type.def x = 1; (1) x--; (2)
-
declare
def x
; implicit castint 1
todef
→def
; storedef
tox
-
load from
x
→def
; implicit castdef
toint 1
; subtractint 1
fromint 1
→int 0
; implicit castint 0
todef
; storedef
tox
-
Use the pre increment operator '++'
to INCREASE the value of a numeric type
variable/field by 1
. An extra implicit cast is necessary to return the
promoted numeric type value to the original numeric type value of the
variable/field for the following types: byte
, short
, and char
. If a
variable/field is read as part of an expression the value is loaded after the
increment.
Errors
-
If the variable/field is a non-numeric type.
Grammar
pre_increment: '++' ( variable | field );
Promotion
original | promoted | implicit |
---|---|---|
byte |
int |
byte |
short |
int |
short |
char |
int |
char |
int |
int |
|
long |
long |
|
float |
float |
|
double |
double |
|
def |
def |
Examples
-
Pre increment with different numeric types.
short i = 0; (1) ++i; (2) long j = 1; (3) long k; (4) k = ++j; (5)
-
declare
short i
; storeshort 0
toi
-
load from
i
→short 0
; promoteshort 0
: resultint
; addint 0
andint 1
→int 1
; implicit castint 1
toshort 1
; storeshort 1
toi
-
declare
long j
; implicit castint 1
tolong 1
→long 1
; storelong 1
toj
-
declare
long k
; store defaultlong 0
tok
-
load from
j
→long 1
; addlong 1
andlong 1
→long 2
; storelong 2
toj
; storelong 2
tok
-
-
Pre increment with the
def
type.def x = 1; (1) ++x; (2)
-
declare
def x
; implicit castint 1
todef
→def
; storedef
tox
-
load from
x
→def
; implicit castdef
toint 1
; addint 1
andint 1
→int 2
; implicit castint 2
todef
; storedef
tox
-
Use the pre decrement operator '--'
to DECREASE the value of a numeric type
variable/field by 1
. An extra implicit cast is necessary to return the
promoted numeric type value to the original numeric type value of the
variable/field for the following types: byte
, short
, and char
. If a
variable/field is read as part of an expression the value is loaded after the
decrement.
Errors
-
If the variable/field is a non-numeric type.
Grammar
pre_decrement: '--' ( variable | field );
Promotion
original | promoted | implicit |
---|---|---|
byte |
int |
byte |
short |
int |
short |
char |
int |
char |
int |
int |
|
long |
long |
|
float |
float |
|
double |
double |
|
def |
def |
Examples
-
Pre decrement with different numeric types.
short i = 0; (1) --i; (2) long j = 1; (3) long k; (4) k = --j; (5)
-
declare
short i
; storeshort 0
toi
-
load from
i
→short 0
; promoteshort 0
: resultint
; subtractint 1
fromint 0
→int -1
; implicit castint -1
toshort -1
; storeshort -1
toi
-
declare
long j
; implicit castint 1
tolong 1
→long 1
; storelong 1
toj
-
declare
long k
; store defaultlong 0
tok
-
load from
j
→long 1
; subtractlong 1
fromlong 1
→long 0
; storelong 0
toj
storelong 0
tok
;
-
-
Pre decrement operator with the
def
type.def x = 1; (1) --x; (2)
-
declare
def x
; implicit castint 1
todef
→def
; storedef
tox
-
load from
x
→def
; implicit castdef
toint 1
; subtractint 1
fromint 1
→int 0
; implicit castint 0
todef
; storedef
tox
-
Use the unary positive operator '+'
to the preserve the IDENTITY of a
numeric type value.
Errors
-
If the value is a non-numeric type.
Grammar
unary_positive: '+' expression;
Examples
-
Unary positive with different numeric types.
int x = +1; (1) long y = +x; (2)
-
declare
int x
; identityint 1
→int 1
; storeint 1
tox
-
declare
long y
; load fromx
→int 1
; identityint 1
→int 1
; implicit castint 1
tolong 1
→long 1
; storelong 1
toy
-
-
Unary positive with the
def
type.def z = +1; (1) int i = +z; (2)
-
declare
def z
; identityint 1
→int 1
; implicit castint 1
todef
; storedef
toz
-
declare
int i
; load fromz
→def
; implicit castdef
toint 1
; identityint 1
→int 1
; storeint 1
toi
;
-
Use the unary negative operator '-'
to NEGATE a numeric type value.
Errors
-
If the value is a non-numeric type.
Grammar
unary_negative: '-' expression;
Examples
-
Unary negative with different numeric types.
int x = -1; (1) long y = -x; (2)
-
declare
int x
; negateint 1
→int -1
; storeint -1
tox
-
declare
long y
; load fromx
→int 1
; negateint -1
→int 1
; implicit castint 1
tolong 1
→long 1
; storelong 1
toy
-
-
Unary negative with the
def
type.def z = -1; (1) int i = -z; (2)
-
declare
def z
; negateint 1
→int -1
; implicit castint -1
todef
; storedef
toz
-
declare
int i
; load fromz
→def
; implicit castdef
toint -1
; negateint -1
→int 1
; storeint 1
toi
;
-
Use the bitwise not operator '~'
to NOT each bit in an integer type value
where a 1-bit
is flipped to a resultant 0-bit
and a 0-bit
is flipped to a
resultant 1-bit
.
Errors
-
If the value is a non-integer type.
Bits
original | result |
---|---|
1 |
0 |
0 |
1 |
Grammar
bitwise_not: '~' expression;
Promotion
original | promoted |
---|---|
byte |
int |
short |
int |
char |
int |
int |
int |
long |
long |
def |
def |
Examples
-
Bitwise not with different numeric types.
byte b = 1; (1) int i = ~b; (2) long l = ~i; (3)
-
declare
byte x
; storebyte 1
to b -
declare
int i
; load fromb
→byte 1
; implicit castbyte 1
toint 1
→int 1
; bitwise notint 1
→int -2
; storeint -2
toi
-
declare
long l
; load fromi
→int -2
; implicit castint -2
tolong -2
→long -2
; bitwise notlong -2
→long 1
; storelong 1
tol
-
-
Bitwise not with the
def
type.def d = 1; (1) def e = ~d; (2)
-
declare
def d
; implicit castint 1
todef
→def
; storedef
tod
; -
declare
def e
; load fromd
→def
; implicit castdef
toint 1
→int 1
; bitwise notint 1
→int -2
; implicit castint 1
todef
→def
; storedef
toe
-
Use the multiplication operator '*'
to MULTIPLY together two numeric type
values. Rules for resultant overflow and NaN values follow the JVM
specification.
Errors
-
If either of the values is a non-numeric type.
Grammar
multiplication: expression '*' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Multiplication with different numeric types.
int i = 5*4; (1) double d = i*7.0; (2)
-
declare
int i
; multiplyint 4
byint 5
→int 20
; storeint 20
ini
-
declare
double d
; load fromint i
→int 20
; promoteint 20
anddouble 7.0
: resultdouble
; implicit castint 20
todouble 20.0
→double 20.0
; multiplydouble 20.0
bydouble 7.0
→double 140.0
; storedouble 140.0
tod
-
-
Multiplication with the
def
type.def x = 5*4; (1) def y = x*2; (2)
-
declare
def x
; multiplyint 5
byint 4
→int 20
; implicit castint 20
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 20
; multiplyint 20
byint 2
→int 40
; implicit castint 40
todef
→def
; storedef
toy
-
Use the division operator '/'
to DIVIDE one numeric type value by another.
Rules for NaN values and division by zero follow the JVM specification. Division
with integer values drops the remainder of the resultant value.
Errors
-
If either of the values is a non-numeric type.
-
If a left-hand side integer type value is divided by a right-hand side integer type value of
0
.
Grammar
division: expression '/' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Division with different numeric types.
int i = 29/4; (1) double d = i/7.0; (2)
-
declare
int i
; divideint 29
byint 4
→int 7
; storeint 7
ini
-
declare
double d
; load fromint i
→int 7
; promoteint 7
anddouble 7.0
: resultdouble
; implicit castint 7
todouble 7.0
→double 7.0
; dividedouble 7.0
bydouble 7.0
→double 1.0
; storedouble 1.0
tod
-
-
Division with the
def
type.def x = 5/4; (1) def y = x/2; (2)
-
declare
def x
; divideint 5
byint 4
→int 1
; implicit castint 1
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 1
; divideint 1
byint 2
→int 0
; implicit castint 0
todef
→def
; storedef
toy
-
Use the remainder operator '%'
to calculate the REMAINDER for division
between two numeric type values. Rules for NaN values and division by zero follow the JVM
specification.
Errors
-
If either of the values is a non-numeric type.
Grammar
remainder: expression '%' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Remainder with different numeric types.
int i = 29%4; (1) double d = i%7.0; (2)
-
declare
int i
; remainderint 29
byint 4
→int 1
; storeint 7
ini
-
declare
double d
; load fromint i
→int 1
; promoteint 1
anddouble 7.0
: resultdouble
; implicit castint 1
todouble 1.0
→double 1.0
; remainderdouble 1.0
bydouble 7.0
→double 1.0
; storedouble 1.0
tod
-
-
Remainder with the
def
type.def x = 5%4; (1) def y = x%2; (2)
-
declare
def x
; remainderint 5
byint 4
→int 1
; implicit castint 1
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 1
; remainderint 1
byint 2
→int 1
; implicit castint 1
todef
→def
; storedef
toy
-
Use the addition operator '+'
to ADD together two numeric type values. Rules
for resultant overflow and NaN values follow the JVM specification.
Errors
-
If either of the values is a non-numeric type.
Grammar
addition: expression '+' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Addition operator with different numeric types.
int i = 29+4; (1) double d = i+7.0; (2)
-
declare
int i
; addint 29
andint 4
→int 33
; storeint 33
ini
-
declare
double d
; load fromint i
→int 33
; promoteint 33
anddouble 7.0
: resultdouble
; implicit castint 33
todouble 33.0
→double 33.0
; adddouble 33.0
anddouble 7.0
→double 40.0
; storedouble 40.0
tod
-
-
Addition with the
def
type.def x = 5+4; (1) def y = x+2; (2)
-
declare
def x
; addint 5
andint 4
→int 9
; implicit castint 9
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 9
; addint 9
andint 2
→int 11
; implicit castint 11
todef
→def
; storedef
toy
-
Use the subtraction operator '-'
to SUBTRACT a right-hand side numeric type
value from a left-hand side numeric type value. Rules for resultant overflow
and NaN values follow the JVM specification.
Errors
-
If either of the values is a non-numeric type.
Grammar
subtraction: expression '-' expression;
Promotion
byte |
short |
char |
int |
long |
float |
double |
def |
|
byte |
int |
int |
int |
int |
long |
float |
double |
def |
short |
int |
int |
int |
int |
long |
float |
double |
def |
char |
int |
int |
int |
int |
long |
float |
double |
def |
int |
int |
int |
int |
int |
long |
float |
double |
def |
long |
long |
long |
long |
long |
long |
float |
double |
def |
float |
float |
float |
float |
float |
float |
float |
double |
def |
double |
double |
double |
double |
double |
double |
double |
double |
def |
def |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Subtraction with different numeric types.
int i = 29-4; (1) double d = i-7.5; (2)
-
declare
int i
; subtractint 4
fromint 29
→int 25
; storeint 25
ini
-
declare
double d
load fromint i
→int 25
; promoteint 25
anddouble 7.5
: resultdouble
; implicit castint 25
todouble 25.0
→double 25.0
; subtractdouble 33.0
bydouble 7.5
→double 25.5
; storedouble 25.5
tod
-
-
Subtraction with the
def
type.def x = 5-4; (1) def y = x-2; (2)
-
declare
def x
; subtractint 4
andint 5
→int 1
; implicit castint 1
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 1
; subtractint 2
fromint 1
→int -1
; implicit castint -1
todef
→def
; storedef
toy
-
Use the left shift operator '<<'
to SHIFT lower order bits to higher order
bits in a left-hand side integer type value by the distance specified in a
right-hand side integer type value.
Errors
-
If either of the values is a non-integer type.
-
If the right-hand side value cannot be cast to an int type.
Grammar
left_shift: expression '<<' expression;
Promotion
The left-hand side integer type value is promoted as specified in the table
below. The right-hand side integer type value is always implicitly cast to an
int
type value and truncated to the number of bits of the promoted type value.
original | promoted |
---|---|
byte |
int |
short |
int |
char |
int |
int |
int |
long |
long |
def |
def |
Examples
-
Left shift with different integer types.
int i = 4 << 1; (1) long l = i << 2L; (2)
-
declare
int i
; left shiftint 4
byint 1
→int 8
; storeint 8
ini
-
declare
long l
load fromint i
→int 8
; implicit castlong 2
toint 2
→int 2
; left shiftint 8
byint 2
→int 32
; implicit castint 32
tolong 32
→long 32
; storelong 32
tol
-
-
Left shift with the
def
type.def x = 4 << 2; (1) def y = x << 1; (2)
-
declare
def x
; left shiftint 4
byint 2
→int 16
; implicit castint 16
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 16
; left shiftint 16
byint 1
→int 32
; implicit castint 32
todef
→def
; storedef
toy
-
Use the right shift operator '>>'
to SHIFT higher order bits to lower order
bits in a left-hand side integer type value by the distance specified in a
right-hand side integer type value. The highest order bit of the left-hand side
integer type value is preserved.
Errors
-
If either of the values is a non-integer type.
-
If the right-hand side value cannot be cast to an int type.
Grammar
right_shift: expression '>>' expression;
Promotion
The left-hand side integer type value is promoted as specified in the table
below. The right-hand side integer type value is always implicitly cast to an
int
type value and truncated to the number of bits of the promoted type value.
original | promoted |
---|---|
byte |
int |
short |
int |
char |
int |
int |
int |
long |
long |
def |
def |
Examples
-
Right shift with different integer types.
int i = 32 >> 1; (1) long l = i >> 2L; (2)
-
declare
int i
; right shiftint 32
byint 1
→int 16
; storeint 16
ini
-
declare
long l
load fromint i
→int 16
; implicit castlong 2
toint 2
→int 2
; right shiftint 16
byint 2
→int 4
; implicit castint 4
tolong 4
→long 4
; storelong 4
tol
-
-
Right shift with the
def
type.def x = 16 >> 2; (1) def y = x >> 1; (2)
-
declare
def x
; right shiftint 16
byint 2
→int 4
; implicit castint 4
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 4
; right shiftint 4
byint 1
→int 2
; implicit castint 2
todef
→def
; storedef
toy
-
Use the unsigned right shift operator '>>>'
to SHIFT higher order bits to
lower order bits in a left-hand side integer type value by the distance
specified in a right-hand side type integer value. The highest order bit of the
left-hand side integer type value is not preserved.
Errors
-
If either of the values is a non-integer type.
-
If the right-hand side value cannot be cast to an int type.
Grammar
unsigned_right_shift: expression '>>>' expression;
Promotion
The left-hand side integer type value is promoted as specified in the table
below. The right-hand side integer type value is always implicitly cast to an
int
type value and truncated to the number of bits of the promoted type value.
original | promoted |
---|---|
byte |
int |
short |
int |
char |
int |
int |
int |
long |
long |
def |
def |
Examples
-
Unsigned right shift with different integer types.
int i = -1 >>> 29; (1) long l = i >>> 2L; (2)
-
declare
int i
; unsigned right shiftint -1
byint 29
→int 7
; storeint 7
ini
-
declare
long l
load fromint i
→int 7
; implicit castlong 2
toint 2
→int 2
; unsigned right shiftint 7
byint 2
→int 3
; implicit castint 3
tolong 3
→long 3
; storelong 3
tol
-
-
Unsigned right shift with the
def
type.def x = 16 >>> 2; (1) def y = x >>> 1; (2)
-
declare
def x
; unsigned right shiftint 16
byint 2
→int 4
; implicit castint 4
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 4
; unsigned right shiftint 4
byint 1
→int 2
; implicit castint 2
todef
→def
; storedef
toy
-
Use the bitwise and operator '&'
to AND together each bit within two
integer type values where if both bits at the same index are 1
the resultant
bit is 1
and 0
otherwise.
Errors
-
If either of the values is a non-integer type.
Bits
1 |
0 |
|
1 |
1 |
0 |
0 |
0 |
0 |
Grammar
bitwise_and: expression '&' expression;
Promotion
byte |
short |
char |
int |
long |
def |
|
byte |
int |
int |
int |
int |
long |
def |
short |
int |
int |
int |
int |
long |
def |
char |
int |
int |
int |
int |
long |
def |
int |
int |
int |
int |
int |
long |
def |
long |
long |
long |
long |
long |
long |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Bitwise and with different integer types.
int i = 5 & 6; (1) long l = i & 5L; (2)
-
declare
int i
; bitwise andint 5
andint 6
→int 4
; storeint 4
ini
-
declare
long l
load fromint i
→int 4
; promoteint 4
andlong 5
: resultlong
; implicit castint 4
tolong 4
→long 4
; bitwise andlong 4
andlong 5
→long 4
; storelong 4
tol
-
-
Bitwise and with the
def
type.def x = 15 & 6; (1) def y = x & 5; (2)
-
declare
def x
; bitwise andint 15
andint 6
→int 6
; implicit castint 6
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 6
; bitwise andint 6
andint 5
→int 4
; implicit castint 4
todef
→def
; storedef
toy
-
Use the bitwise xor operator '^'
to XOR together each bit within two integer
type values where if one bit is a 1
and the other bit is a 0
at the same
index the resultant bit is 1
otherwise the resultant bit is 0
.
Errors
-
If either of the values is a non-integer type.
Bits
The following table illustrates the resultant bit from the xoring of two bits.
1 |
0 |
|
1 |
0 |
1 |
0 |
1 |
0 |
Grammar
bitwise_xor: expression '^' expression;
Promotion
byte |
short |
char |
int |
long |
def |
|
byte |
int |
int |
int |
int |
long |
def |
short |
int |
int |
int |
int |
long |
def |
char |
int |
int |
int |
int |
long |
def |
int |
int |
int |
int |
int |
long |
def |
long |
long |
long |
long |
long |
long |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Bitwise xor with different integer types.
int i = 5 ^ 6; (1) long l = i ^ 5L; (2)
-
declare
int i
; bitwise xorint 5
andint 6
→int 3
; storeint 3
ini
-
declare
long l
load fromint i
→int 4
; promoteint 3
andlong 5
: resultlong
; implicit castint 3
tolong 3
→long 3
; bitwise xorlong 3
andlong 5
→long 6
; storelong 6
tol
-
-
Bitwise xor with the
def
type.def x = 15 ^ 6; (1) def y = x ^ 5; (2)
-
declare
def x
; bitwise xorint 15
andint 6
→int 9
; implicit castint 9
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 9
; bitwise xorint 9
andint 5
→int 12
; implicit castint 12
todef
→def
; storedef
toy
-
Use the bitwise or operator '|'
to OR together each bit within two integer
type values where if at least one bit is a 1
at the same index the resultant
bit is 1
otherwise the resultant bit is 0
.
Errors
-
If either of the values is a non-integer type.
Bits
The following table illustrates the resultant bit from the oring of two bits.
1 |
0 |
|
1 |
1 |
1 |
0 |
1 |
0 |
Grammar
bitwise_or: expression '|' expression;
Promotion
byte |
short |
char |
int |
long |
def |
|
byte |
int |
int |
int |
int |
long |
def |
short |
int |
int |
int |
int |
long |
def |
char |
int |
int |
int |
int |
long |
def |
int |
int |
int |
int |
int |
long |
def |
long |
long |
long |
long |
long |
long |
def |
def |
def |
def |
def |
def |
def |
def |
Examples
-
Bitwise or with different integer types.
int i = 5 | 6; (1) long l = i | 8L; (2)
-
declare
int i
; bitwise orint 5
andint 6
→int 7
; storeint 7
ini
-
declare
long l
load fromint i
→int 7
; promoteint 7
andlong 8
: resultlong
; implicit castint 7
tolong 7
→long 7
; bitwise orlong 7
andlong 8
→long 15
; storelong 15
tol
-
-
Bitwise or with the
def
type.def x = 5 ^ 6; (1) def y = x ^ 8; (2)
-
declare
def x
; bitwise orint 5
andint 6
→int 7
; implicit castint 7
todef
→def
; storedef
inx
-
declare
def y
; load fromx
→def
; implicit castdef
toint 7
; bitwise orint 7
andint 8
→int 15
; implicit castint 15
todef
→def
; storedef
toy
-