Home Discussion Discuss: Convert Hexadecimal into Binary and Long

  • hm?anon September 2, 2011 at 2:19 AM

    how can this work? converting the string hex to int is not gonna fly - > what if the hex number happens to contain an (A-F) hex val? how would int handle that?

  • Wrongnufan October 12, 2011 at 10:04 PM

    Wow, this is pretty wrong.. hexavalue 14 = 16^1*1 + 16^0*4 = 20 in dec.. but 20 in dec is NOT 1110 in bin.. It's 10100. Integer.toBinaryString(i) needs a decimal number, but you put in 14 meaning hex.

  • Thanx!!java_p November 6, 2011 at 1:43 AM

    thank u very much for this splendid piece of code!!

  • ConvertAlex January 25, 2012 at 3:38 PM

    What about I enter a hexa value like: A, B, 9B ?

  • ConverterAlex January 25, 2012 at 3:42 PM

    And one thing more, .toBinaryString() does not return first digits if this are "0". Integer.toBinaryString(3) return 11 not 0011.

  • 64 bit Hex to binary conversionMonesh Kumar February 24, 2012 at 3:07 PM

    public class HexData { public static void main(String[] args) { String hexData = "0023456789ABCDEF"; long longData; String binData = null; int balZero = 0; System.out.println("Hex Data : " + hexData); longData = Long.parseLong(hexData, 16); System.out.println("Long Data : " + longData); binData = Long.toBinaryString(longData); balZero = (64 - (binData.length()-1)); for(int i=1;i<balZero;i++) { binData = "0" + binData; } System.out.println("Bin Data : " + binData); } }

  • Rectify mistake Manjeet Harsh March 29, 2012 at 2:03 AM

    The logic of conversion from Hexadecimal to Integer is wrong. 14 should have been converted into 10100 binary equivalent. And the binary 1110 is equivalent to E in Hexadecimal.

  • ErrorVibhav Sinha August 5, 2012 at 9:45 PM

    How can you parseInt a String having non digit characters. It is giving error.

  • Hexidecimal to Binary Conversion FixPancho Delgado August 10, 2012 at 8:20 AM

    int i = Integer.parseInt(hex); should be int i = Integer.parseInt(hex,16); to accomodate a-f Change that and it works great - Thank you so much for the example.

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Tips and Examples

Convert Hexadecimal into Binary and Long
Convert Hexadecimal into Binary and Long   ... the hexadecimal data into the binary and long format. The java.lang package provides the functionality to convert a hexadecimal to binary and long type data.  Code 

Java Tips and Examples

Convert Binary to Hexadecimal
Convert Binary to Hexadecimal       In this section, you will learn to convert binary data into hexadecimal.  The java.lang package provides the functionality to convert 

Java Beginners

How to convert long to hexadecimal - Java Beginners
How to convert long to hexadecimal  Dear all, anyone know how to convert long data to hexadecimal, please send me the information. Thanks  Hi friend, Returns the hexadecimal string it consists of a long value 

Java Beginners

how to convert all the pixel value to hexadecimal and from hexadecimal to binary in vb.net
how to convert all the pixel value to hexadecimal and from hexadecimal to binary in vb.net   actually i need in vb.net that category... that i need to convert all the pixel values into hexadecimal how it can be done 

Java Tips and Examples

Convert integer type data into binary, octal and hexadecimal
Convert integer type data into binary, octal and hexadecimal... will learn how to convert an integer type data into binary, octal and hexadecimal... into binary, octal, and hexadecimal. The following program helps you to convert 

UML Questions

hexadecimal conversion java compilation - UML
hexadecimal conversion java compilation  write a simple program (in any language of your choice) that accepts a program of 12 binary digits) and converts them to both decimal and hexadecimal as outputs  Hi Friend 

Java Code Examples

Java Convert Octal to Binary
Java Convert Octal to Binary In this tutorial, you will learn how to convert octal to binary. Java has provide different ways to change the number system of different numbers. You can convert and decimal to octal, decimal to binary 

Java Beginners

decimal to hexadecimal
decimal to hexadecimal  using array in java convert decimal to hexadecimal.   Hi, Please see the example Convert Decimal to Hexadecimal. Thanks 

IDE Questions

binary
binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. Thks 

Java Tips and Examples

Convert String into long in java
Convert String into long in java In this section you will learn about... then you can convert string to long by the following same procedure. You need.... Converting  String to long using valueOf() method : You can convert string to long  

Java-Tutorials

Java Write To File Binary
Java Write To File Binary In this tutorial you will learn how to write to binary file. A binary file is a file into which the bit patterns of mostly data types can be formed to a byte of 8 bits. Write to a binary file in java 

Java Tips and Examples

Convert Binary to Decimal
Convert Binary to Decimal       In this section, you will learn how to convert a  binary... to convert the integer data into the binary to decimal.  Code Description 

Java Beginners

Hexadecimal numbers multiplication
Hexadecimal numbers multiplication  Sir, I have to multiply 128 bit hexadecimal numbers. Do u have any logic for this?? The numbers are like ab7564fa342b5412c34d9e67ab341b58 

General

Java Conversion
to convert a hexadecimal to binary and long type data.    Convert... number into hexadecimal. Convert Binary to Decimal In this section... into the binary to decimal.  Convert Binary to Hexadecimal In this section 

Java Beginners

Java Binary data file - Java Beginners
Java Binary data file  Hi, I have a binary data file(binfile.data... of consecutive long values -some number of consecutive float values -some number... in the binary file.I have to do this using java.I tried to figure out the correct 

General

Reading binary file into byte array in Java
Example code of reading binary file into byte array in Java This example shows you how to read a binary file into byte array from Java program. This type of example code is need where you have to read the binary data into byte array 

Java Tips and Examples

Convert Hexadecimal to Decimal
Convert Hexadecimal to Decimal       In this section, you will learn to change hexadecimal number... by the second argument. Here the second argument is 16  to convert a hexadecimal 

Java Tips and Examples

Convert Decimal to Hexadecimal
Convert Decimal to Hexadecimal       In this section, you will learn to convert a decimal data into hexadecimal. The java.lang package provides the functionality to convert a decimal 

Struts Questions

long validate
long validate  How to validate long type 

Java Tips and Examples

Convert Hexadecimal number into Integer
to convert hexadecimal data into integer. The java.lang package provides the functionally to convert the hexadecimal data into an integer type data.  Code... Convert Hexadecimal number into Integer  

Java Beginners

Binary tree
Binary tree  a. Construct a method to implement a binary tree using an array. b. Implement the binary tree to store numbers in sorted order 

Java Beginners

Binary tree
Binary tree  hii, What is binary tree?   hello, A binary tree is a tree in which every node has exactly two links i.e left and right link 

Java Beginners

binary tree
binary tree  can a binary tree be implemented with out comparing...://www.roseindia.net/java/java-get-example/java-binary-tree-code.shtml http://www.roseindia.net/java/java-get-example/java-binary-tree-insert.shtml 

PHP Questions

binary tree
binary tree  how to count no. of nodes in a binary tree for mlm if it complet tree or incomplet tree in php using mysql db 

Java Beginners

octal to binary
octal to binary  i want to know how to convert a octal to binary number   Here is a java example that converts octal to binary. import... binary=Integer.toBinaryString(i); System.out.println(binary 

IDE Questions

program binary
program binary  Hi I want to write a program in pascal that ask a user to input a decimal number and then return its binary equivalent in the minimum number of bits required to repesent the number. In pascal language please 

Java Beginners

conversion from decimal to hexadecimal and vice versa
conversion from decimal to hexadecimal and vice versa  can i get the code for converting decimal to hexadecimal   Here is a code that converts decimal to hexadecimal. import java.io.*; public class 

General

Convert Byte to Hexadecimal
Convert Byte to Hexadecimal       In this section, We are going to convert a byte value into a hexadecimal number. The package java.lang provides the functionality 

Java Beginners

Binary Search - Java Beginners
Binary Search  how to use Binary think in java give me the Binary Search programm thx 

Java Technology Tutorials

Java display file content in hexadecimal format
Java display file content in hexadecimal format In this section, you will learn how to read the file content and display it in hexadecimal format. Reading... in hexadecimal format. For this we have used FileInputStream class to open a file 

DMCA.com