Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a byte type from a String in Java

Tags:

java

byte

I have this string 11110000, which represents a byte.

I want to create a byte from that string, but I can't find any example on-line.

Can someone please help me?

like image 711
kakush Avatar asked Aug 30 '26 21:08

kakush


2 Answers

int value = Integer.parseInt(s, 2); // 2 for binary

If you want byte type:

byte value = Byte.parseByte(s, 2); // 2 for binary

like image 72
dacongy Avatar answered Sep 02 '26 10:09

dacongy


Use Byte#parseByte().

like image 45
Matt Ball Avatar answered Sep 02 '26 10:09

Matt Ball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!