- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert a byte to hexadecimal equivalent in Java
To convert a byte to hexadecimal equivalent, use the toHexString() method in Java.
Firstly, let us take a byte value.
byte val1 = (byte)90;
Before using the method, let us do some more manipulations. Mask the byte value now:
int res = val1 & 0xFF;
Let us now see the complete example and use the toHexString() method to convert a byte to hexadecimal equivalent.
Example
public class Demo { public static void main(String[] args) { byte val1 = (byte)90; System.out.println("Byte = "+val1); int res = val1 & 0xFF; System.out.println("Hexadecimal = "+Integer.toHexString(res)); } }
Output
Byte = 90 Hexadecimal = 5a
- Related Articles
- How can we convert a hexadecimal value to a byte in Java?
- Convert byte primitive type to Byte object in Java
- Convert byte to String in Java
- Convert a String to a byte number in Java
- How to convert Decimal to Hexadecimal in Java
- Java Program to convert integer to hexadecimal
- JAVA Program to Convert Octal to Hexadecimal
- JAVA program to Convert Hexadecimal to Binary
- How to convert a PDF to byte array in Java?
- Convert decimal integer to hexadecimal number in Java
- Java Program to convert byte to string
- Java Program to convert string to byte
- Convert byte Array to Hex String in Java
- Convert Hex String to byte Array in Java
- Java Program to convert an UNSIGNED byte to a JAVA type

Advertisements