0

I understand that java uses two's complement to represent a byte type. However is there an easy way to parse a string representing numbers in range of 0-255 into a byte?

E.g. I expect the following code to be able to parse values (218,230,etc.)

Byte.valueOf((String) value)
Y.S
  • 1,860
  • 3
  • 17
  • 30
  • Byte in java is signed meaning it has a minimum of -128 or a maximum of 127. You will need to use a different type to represent your unsigned value. –  Sep 04 '17 at 09:04
  • You can use `Byte.parseByte(value)` to parse a byte. I don't know what you mean with a "signed tinyint (0-255)" though. That value range is unsigned. – marstran Sep 04 '17 at 09:05
  • 1
    if you have a string between 0-255 then use an integer – ΦXocę 웃 Пepeúpa ツ Sep 04 '17 at 09:08
  • in java you cannot do the same thing as in SQL, so for a signed `tinyint` you should use a `shortint` or as here `int`(https://docs.oracle.com/javase/7/docs/api/java/sql/Types.html#TINYINT). Also check this: https://stackoverflow.com/questions/3108297/james-goslings-explanation-of-why-javas-byte-is-signed – Edwin Sep 04 '17 at 09:14

0 Answers0