DragonControl:
Trying to have user input a number sometimes with a decimal point sometimes without via the serial window.
I want to convert this number to hex and store it in an array to then send out over ethernetUdp
A: Background Information:
1. I have this number: 139; I can make one of the following declarations to store this number in a memory location of the MCU with the understanding and acceptance that data/number is always saved in bit/binary form.
(1)
byte y = 139; //user has written data/number in the program source code in human format
Serial.println(y, BIN); //Serial Monitor shows: 10001011
(2)
byte y = 0x8B; //user has written data/number in the program source code in hexadecimal format
Serial.println(y, BIN); //Serial Monitor shows: 10001011
(3)
byte y = 0b10001011; ////user has written data in the program source code in bit/binary format
Serial.println(y, BIN); //Serial Monitor shows: 10001011
(4) The following is the actual storage pattern of the given number/data 139 in the memory location of the MCU.

2. The morale of the story is:
The data/number is always stored in computer/MCU memory in bit form regardless of the format that the user follows to write data in the source code of the program.
3. The following data: 11000110 is found in an arbitrary memory location. How much is it to a human being? Is it 134 or -58 or 'Common Anode (CA) code for Character C'?
The answer depends on 'what keyword' the unknown user put in the program to store this data in the computer memory.
(1) If the used keyword was 'byte', the number would be: 134.
(2) If the used keyword was 'signed char' or 'int8_t', the number would be -58.
(3) It is a CA-code if the bit pattern was derived manually from a 'Character Vs CA-code Lookup Table'.
B: Case Study
The number 14.53 is received by Arduino from the PC via Serial Port. How to save it in a variable as binary?
1. It is said that the number has already been received and now assume that the received number has also been saved in a variable 'float x;. That is we have:
float x = 14.53;
2. The variable x of Step-1 refers to the following 4 memory locations which contain this bit pattern: 01000001 01101000 01110001 11100001 for the number 14.53. There are 32 bits and they can be written in compact form using hex format like this: 416871E1. (This is just to seen on paper; the actual storage is always in bit/binary form.)

3. We can use the following union data structure to save the 32-bit data of Step-2 into 4 members of an array; where, low indexed member of the array contains lower byte of the 32-bit data.
union
{
float x;
byte myArray[4];
}data;
data.x = 14.53;
Serial.println(data.myArray[0], HEX); //shows: E1
..........
4. You may ask the question -- how do we know that 01000001 01101000 01110001 11100001 is the bit pattern that has been stored against the number 14.53? Let us execute the following codes:
Serial.println(*(unsigned long*)&x, BIN); //shows: 1000001011010000111000111100001 (leading 0 missing)
Serial.println(*(unsigned long*)&x, HEX); //shows: 41687AE1

