Trying to convert hex into a bin file, but, get a NumberFormat Exception

Hi, dear gentlemen and ladies.

I’m developing a program that reads a file contained in an SD card via Arduino and prints the data of this file in hexadecimal format. At the same time, I am trying to create a program in Processing that receives this hexadecimal data from Arduino and writes a binary file.

But my program in Processing, is giving me an error of type “NumberFormatException: for input String […]”. And this error, does not allow me to create my binary file. Below is my Arduino code.


//27 march 2019

// sd card hex dump
// based on Lucario448's code in #2 here https://forum.arduino.cc/index.php?topic=605875
//

#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;

File file;

void setup()
{
  Serial.begin(115200);
 for (int seconds = 10; seconds >= 0; seconds--)
    {
       
        delay(1000);
    }



  openFileOnSD();
 //remember to edit the file name into the function <<<<<<<<<<<<<<<<
  if (file) dumpTheOpenedFile();
delay (5);

 
 //Serial.write(file.read());
} //setup

void loop()
{

} //loop

void openFileOnSD()
{


  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present ******************");
    // don't do anything more:
    return;
  }
 // Serial.println("Card initialized.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  file = SD.open("picture.jpg"); //<<<<<<<<<<<<<<<<<<< set the name here <<<<<<<<<<<<<<<
 //printDirectory(file, 0);
  if (file)
  {

    delay(150);
  }
  // if the file isn't open, pop up an error:
  else
  {
    Serial.println("Error opening file... check the name ******************");
  }
}

void dumpTheOpenedFile()
{
 // Assuming the file is already opened for reading.

const byte bytesPerRow = 16; // 4 as minimum

char hexVal[9];
byte buffer[bytesPerRow];

file.seek(0);
// Typing file's content
while (file.available()) {

       byte amount = file.read(buffer, bytesPerRow);
   
    //Print hex values
    for (byte i = 0; i < amount; i++)
   {
      sprintf(hexVal, "%02X",  buffer[i]);
      Serial.print(hexVal);
    }

  
Serial.println(); // Next line
} // End of while loop
  Serial.println("END");

file.close();
 pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
    for (unsigned int counter = 0; counter < 5; counter++)
    {
        delay(1000);
    }
} //dumpTheOpenedFile

Arduino prints the hex data in this way:

E4F6DEDEFEF6D34900624A4A1A524049
B8FCF6FEFCF6FE9C005852465852C69C
F7FFC6F6FEC6F67A007B42027A42027A
38BCF6F6F6F6FE5C001852525252465C
END

Now, this is my Processing code:

import processing.serial.*;

Serial myPort;
String val;
  
PrintWriter output;


void setup()
{
  String portName = "COM4";
    
   myPort = new Serial(this, portName, 115200);
output = createWriter("C:\\Users\\DRSF\\Documents\\pic.bin"); 
   
}


void draw()
{
  
   if ( myPort.available() > 0) 
  {  // If data is available,
  val = myPort.readString();    
  delay(500);
  } 
println(val); //print it out in the console

  if ( val!= null && val!="END") {
    String serialArdu;
    serialArdu = val;
    hexToBinary(serialArdu);
  output.println(serialArdu);
  }
  if (val=="END"){
    output.flush(); 
   
    
    // Writes the remaining data to the file
  output.close();  // Finishes the file
    
  }
}



String hexToBinary(String hex) {
      
       int i = Integer.parseInt(hex,16);
      
      String bin = Integer.toBinaryString(i);
      return bin;
      
    }

I have tried to convert the values to long, following a suggestion I saw in this same forum, but I still have the same errors.

I created a similar program in .NET. This program prints the data coming from the Arduino into a (pseudo) serial monitor and converts them successfully into a binary file. I would like to accomplish the same thing with Processing.
Any help will be appreciated.

*Edit: I’m Using Processing 3.4 IDE and Arduino 1.0.5 r2 in a Windows 7 Ultimate 64 bits machine.

Thanks in advance.

1 Like

Could you post the full error?

1 Like

Good morning, Sir Tony! Forgive me for taking time to respond. Problems with working hours. Forgive me. Yes, I will now post the error message. Forgive me for not posting it before. I am not experienced, but this error, seems to me that Processing doesn’t separate the lines of 32 characters from Arduino Serial and then, this error happens.

This is the error message:

NumberFormatException: For input string: "4E45531A010101000000000000000000
78D8A2408E1740A2FF9AE88E00208E01
208E104020B8C0A9009D00009D00019D
00029D00049D00059D00069D0007A9FE
9D0003E8D0E120B8C0AD0220A93F8D06
20A9008D0620A200BD00E08D0720E8E0
20D0F5A200BD40E09D0002E8E02"

Thank you.

2 Likes

Hey There !

First you have to convert the hex to decimal then you can do .toBinaryString. So try something like this

long conv = Long.parseLong( yourstring , 16 );
String bin = conv;
bin.toBinaryString();

1 Like

Hi, Sir, InferNova. Good Morning!

Sure! I’ll try.

Thank you!
1 Like

Well, trying with long, but, I get the same error. But thank you.

new code, according to your suggestion:

String hexToBinary(String hex) {
      
       //int i =  Integer.parseInt(hex,16);
      
      //String bin = Integer.toBinaryString(i);
      //return bin;
      
      long conv = Long.parseLong( hex, 16 );
       String bin = Long.toBinaryString(conv);
         return bin;
      
    }

Error message:

NumberFormatException: For input string: "5531A010101000000000000000000
78D8A2408E1740A2FF9AE88E00208E01
208E104020B8C0A9009D00009D00019D
00029D00049D00059D00069D0007A9FE
9D0003E8D0E120B8C0AD0220A93F8D06
20A9008D0620A200BD00E08D0720E8E0
20D0F5A200BD40E09D0002E8E028D0F5
A9888D0020A9108D0120AD00048D0000
4C70C0A9008D0320A9028D1440AD0000
2991D002F031AD0220A93F8D0620A900
8D0620A200BD20E08D0720E8E020D0F5
A200BD68E09D0002E8E028D0F5A9888D
0020A9108D0120402C022010FB6060FF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFF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F
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
"

Actually thinking about it and taking this value into account this is wayyy to big to be put into long which hence is causing the number format exception. Using BigInteger in this case is way more effective.

import java.math.BigInteger;
String hex = "5531A01010100000000000000000078D8A2408E1740A2FF9AE88E00208E01208E104020B8C0A9009D00009D00019D00029D00049D00059D00069D0007A9FE9D0003E8D0E120B8C0AD0220A93F8D0620A9008D0620A200BD00E08D0720E8E020D0F5A200BD40E09D0002E8E028D0F5A9888D0020A9108D0120AD00048D00004C70C0A9008D0320A9028D1440AD00002991D002F031AD0220A93F8D0620A9008D0620A200BD20E08D0720E8E020D0F5A200BD68E09D0002E8E028D0F5A9888D0020A9108D0120402C022010FB6060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FF";

BigInteger a = new BigInteger(hex , 16);
print(a.toString(2));
1 Like

Hi, Sir. I came to think that this time, it would work correctly, but unfortunately, I still get errors of type “NumberFormatException”.

This is my current code according to your suggestion:

String hexToBinary(String hex) {
     
       BigInteger i =  new BigInteger(hex,16);
     
     String bin = i.toString(2);
   
     
     return bin;
      
    }

This is the Error Message from console:

NumberFormatException: For input string: "
78D8A"

Thank you again, Sir.

1 Like

Interesting. This works for me. Did you just try test the parsing function itself with the raw hex number you posted ? Because for me it works. Maybe there’s another issue in the code then ?

Do you still get the issue if you just run this in a separate sketch ?

import java.math.BigInteger;
void setup() {
  size(10, 10);
  String hex = "5531A01010100000000000000000078D8A2408E1740A2FF9AE88E00208E01208E104020B8C0A9009D00009D00019D00029D00049D00059D00069D0007A9FE9D0003E8D0E120B8C0AD0220A93F8D0620A9008D0620A200BD00E08D0720E8E020D0F5A200BD40E09D0002E8E028D0F5A9888D0020A9108D0120AD00048D00004C70C0A9008D0320A9028D1440AD00002991D002F031AD0220A93F8D0620A9008D0620A200BD20E08D0720E8E020D0F5A200BD68E09D0002E8E028D0F5A9888D0020A9108D0120402C022010FB6060FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF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FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
  print(hexToBinary(hex));
}

String hexToBinary(String hex) {
  BigInteger i =  new BigInteger(hex, 16);
  String bin = i.toString(2);
  return bin;
}
1 Like

I’ll try it now. Thank you, Sir!

1 Like

Let me try to explain, Sir. Your code works perfectly, according to your example. I tested it and it worked. But I’m trying to do this, with the hex data coming through the Arduino Serial port. I need the Processing to take this hex data and convert it into machine language, in a bin file that will run on an image software.

The idea is: Processing expects the Arduino to complete the process of printing data to the serial port. Then, Processing program picks up all these printed hex data and converts them as I described earlier.

How could I do that?

Thank you!

In your code

 serialArdu = val;
    hexToBinary(serialArdu);
  output.println(serialArdu);

The serial ardu String is never updated it should look something like this.

 serialArdu = val;
 serialArdu = hexToBinary(serialArdu);
 output.println(serialArdu);

This should solve the problem!

1 Like

Sir InferNova. I am deeply grateful for your help. But unfortunately, to our frustration, once again I am getting errors. The error information is now " ’ NumberFormatException: For input string: 000000 ’ " I didn’t think it would be hard. All my day off, basically.

The Arduino code remains the same as I described at the beginning of the topic.

Next, is the current Processing code ( I change the directory path) :

import processing.serial.*;
import java.math.BigInteger;

Serial myPort;
String val;
 String serialArdu; 
PrintWriter output;


void setup()
{
  String portName = "COM4";
    
   myPort = new Serial(this, portName, 115200);
output = createWriter("C:\\MyPic\\mypic.bin"); 
   
}


void draw()
{
  
   if ( myPort.available() > 0) 
  {  // If data is available,
  val = myPort.readString();    
 // delay(500);
  } 
println(val); //print it out in the console

  if ( val!= null && val!="END") {
    
    serialArdu = val;
 serialArdu = hexToBinary(serialArdu);
 output.println(serialArdu);
  }
  if (val=="END"){
    output.flush(); 
   
    
    // Writes the remaining data to the file
  output.close();  // Finishes the file
    
  }
}



String hexToBinary(String hex) {
      
    BigInteger i = new BigInteger(hex , 16);

      
      String bin = i.toString(2);
      return bin;
      
    }

Thank you, Sir!

1 Like

I am gonna get my arduino and see this myself fully !

1 Like

I’m really appreciate, Sir.

With my Arduino code, you can extract hex data from any file type.

I am a very weak programmer. The help of experienced people like yours, always contributes to my learning.

Thank you!

1 Like

I have solved it !

The arduino when sending through serial creates white-spaces when trying to parse these to be a number obviously there are not so therefore it throws the numberformat exception. Also when comparing Strings we do not use == but we use .equals method or .matches for regex here’s the code:

import processing.serial.*;
import java.math.BigInteger;

Serial myPort;
String val;
String serialArdu; 
PrintWriter output;


void setup()
{
  String portName = "COM4";

  myPort = new Serial(this, portName, 115200);
  output = createWriter("C:\\MyPic\\mypic.bin");
}


void draw()
{

  if ( myPort.available() > 0) 
  {  // If data is available,
    val = myPort.readString();   
    val = val.trim();
    // delay(500);
  } 
  println(val); //print it out in the console

  if ( val!= null && val.equals("END")==false) {

    serialArdu = val;
    serialArdu = hexToBinary(serialArdu);
    println(serialArdu);
    output.println(serialArdu);
  }
  if (val!=null && val.equals("END") ) {
    output.flush(); 


    // Writes the remaining data to the file
    output.close();  // Finishes the file
    exit();//Will close the program change if you don't want
  }
}



String hexToBinary(String hex) {

  BigInteger i = new BigInteger(hex, 16);
  String bin = i.toString(2);
  return bin;
}
3 Likes

Sir, Again, I greatly appreciate your help. But unfortunately, for me here, it didn’t work. Honestly, I do not understand. I copied and pasted your Processing code. The Arduino code is the same, but I still get the same errors.

The error message is:

NumberFormatException: For input string: "00000
"

I can’t understand it. Doesn’t make sense.

Would it be my IDE version of Processing? I’m using version 3.4

As I said, my Arduino is Arduino UNO, rev3, and the IDE is 1.0.5 r2. I use this old version because of the correct compilation of the V-USB libraries.

And my Windows is Windows 7, 64-bit, Ultimate.

There is no identification on my micro Sd Card module. But it is lioke the commonly used module, probably made in China.

I really appreciate you trying to help me. I can’t see the reason for my problem.

Thank you, sir.

1 Like

I used this arduino code. It is probably within your arduino code maybe try to change the print to println and remove the println spacing. Here’s the arduino code I used.

Unfortunately I have to go now I will look at this tomorrow.

//27 march 2019

// sd card hex dump
// based on Lucario448's code in #2 here https://forum.arduino.cc/index.php?topic=605875
//

#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;

File file;

void setup()
{
  Serial.begin(115200);
  for (int seconds = 10; seconds >= 0; seconds--)
  {
    Serial.println(0xFFF);
    delay(1000);
  }
  Serial.println("END");
  //remember to edit the file name into the function <<<<<<<<<<<<<<<<
 
  //Serial.write(file.read());
} //setup

void loop()
{

} //loop
3 Likes

In your arduino code where your sending the values in sd add a delay within the loop. This could be causing the issue that data is send to quickly and END is stuck at the end of the numbers which will cause to give exception. That what I tried with my mini version and happened add delay(1000) in sd while loop.

3 Likes

Your help was amazing, Sir! I appreciate it. I am very satisfied. Even though my code won’t work, I could learn a lot. You showed me a lot of important things for making functional code. I really appreciate it. Yes, go rest, Sir. You help me a lot. I also need to rest. Tomorrow, I wake up very early. It’s very late now, here in South America.

I’ll take some time for this project. Next time, I will operate it again.

Thank you so much, Sir!

Best regards!