Data conversion error

Good Day,

I have mod the following code which read from a sdcard to a array, the code read from a input text file "Maxx.txt" to array. everything works fine but there is some data conversion issue.

The binary to decimal conversion is wrong.

The following input text:

04,B11110000,B00001111,B00011100,B11000000

the output is

Initializing SD card...card initialized.
4
4 Fields recieved:
112
87
92
192

but binary to decimal for:
11110000=240, 00001111=15, 00011100=28, 11000000 = 192

THis is the following arduino code

#include <SD.h>
const int chipSelect =10;
int fieldIndex = 0; 

void setup()
{
 Serial.begin(9600);
 Serial.print("Initializing SD card...");
 if (!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");

//---------------------------------------------------------------------------
  File dataFile = SD.open("Maxx.txt");

  if (dataFile)
  {
    int ch = dataFile.read();  
    int NoF = 10 * (ch-'0');    
    ch = dataFile.read();   
    NoF = NoF + ch-'0';   
    ch = dataFile.read(); 
    char me = ch;
    Serial.println(NoF);
    unsigned char values[NoF];  //This is the array to hold the values.
        
    while (dataFile.available())
    {
      for(fieldIndex = 0; fieldIndex < NoF; fieldIndex ++)
      {
        values[fieldIndex]=dataFile.parseInt();
      }
      Serial.print(fieldIndex);
      Serial.println(" Fields recieved:");
      for(int i = 0; i < fieldIndex; i++)
      {
        Serial.println(values[i]);
      }
      fieldIndex = 0;
    }
dataFile.close();
  }
else
  {
    Serial.println("error opening Maxx.txt");
  } 
}

void loop()
{
}

i am newbie to data conversion, so please guide

Does parseInt support a B prefix?

https://www.google.com/search?q=convert+11110000+to+hexadecimal
https://www.google.com/search?q=convert+0x70+to+decimal
...gives 112. That's the first value.

https://www.google.com/search?q=convert+1111+to+hexadecimal
https://www.google.com/search?q=convert+0x57+to+decimal
...gives 87. That's the second value.

https://www.google.com/search?q=convert+11100+to+hexadecimal
https://www.google.com/search?q=convert+0x5C+to+decimal
...gives 92. That's the third value.

https://www.google.com/search?q=convert+11000000+to+hexadecimal
https://www.google.com/search?q=convert+0xC0+to+decimal
...gives 192. That's the fourth value.

The answer is "no". parseInt does not support a B prefix. The values are treated as signed long integers (11110000, 1111, 11100, and 11000000).

You are going to need a new parser or a different file format.

Please can you guide about parser types or point me a webpage where i can lookout, google is throwing a lot, am confused a bit

The values are treated as signed long integers (11110000, 1111, 11100, and 11000000). as you say but i want to treat as unsigned char.

It should be quite easy to read a binary value from a file:

#define ASCII_0 48
#define ASCII_1 49

unsigned int readBinary(File fromFile) {
  unsigned int intValue = 0;
  while (fromFile.available()) {
    int p = fromFile.read();
    if (p == ASCII_0) intValue = intValue << 1;
    else if (p == ASCII_1) intValue = (intValue << 1) & 1;
    else return intValue;
  }
  return intValue;
}

Modifications are required if the code must work in your usecase.