kecoliva
kecoliva

Reputation: 80

How to cast integer to byte in Python but with as same behavior in Java?

In Java for example:

int i = 171;
(byte) i; // will return -85

Is there a way to replicate this behavior in Python? I've already tried a bunch of things but I can't seem to replicate how it works in Java.

Upvotes: 0

Views: 59

Answers (1)

kecoliva
kecoliva

Reputation: 80

Apparently, this is how it's done:

int.from_bytes(bytes([171]), byteorder='big', signed=True)

Upvotes: 1

Related Questions