Formatting String to Hex

Hello, I would like to format a string to unsigned long

"0x11" to 0x11

Serial.println("Enter # of bytes to read (i.e. 00000024 in hex:) ");
while (Serial.available()==0)
{ //Wait for user input

}
NumOfBytes = Serial.readString();

NumOfBytes1 = Hex + NumOfBytes.substring(0,2);
Byte1 = NumOfBytes1.toInt();

Byte1's result is just 0 instead of 0x00.

What OP wants to do, apparently, is convert a String that contains "0x11" to 17 (0x11). The toInt() method won't do that, because it, rightly, expects the string to be a base 10 representation of the value.

OP: Stop using Strings. You can pass a string (which is NOT the same as a String) to strtoul(), which can interpret numbers in any base, to get an unsigned long.