in java
System.out.println((byte) (31330 >> 4));
output : -90
in javascript
console.log(31330 >> 4);
output : 1958
how to get output -90 in javascript like cast (byte) in java?
asked May 22, 2021 at 18:55
1 Answer 1
In JS there's no byte type, but we've got "array of bytes", so you can create an array from your expression and then pick the first element:
console.log(new Int8Array([31330 >> 4])[0])
answered May 22, 2021 at 19:12
Sign up to request clarification or add additional context in comments.
Comments
default
<<and>>) work with signed 32-bit integers. There isn't exactly abytetype in JavaScript.