Convert Long Int to 4 Hex Bytes

//=======Preamble======
I am working on sending commands from an Arduino to a closed loop stepper motion controller using an RS485 module.
Everything on that side is working great and it is receiving byte array commands and doing what its told.
Anyway, I am using the PC software to decipher all the various commands the motion controller will accept as outlined in the picture attached.
Obviously, I want to be able to put my own parameters into these functions so I don't want to manually create each byte array just by copy-pasting the commands from the PC example app.
For the short int values, which are sent as 2 hex bytes, I have been using highByte() and lowByte() to insert these into my array.
For Example:
17682 = 0x4512
but in one other command, I seem to need 2 separate bytes and ALSO they seem to be low first high later so...
lowByte(17682) = 0x12
highByte(17682) = 0x45
thus I would send {0x12, 0x45} (Which is all working great!)

Actual Question:

My problem now is that long values are expected by the controller as 4 separate bytes.

As in my example picture attached, for a position of 270000, the program expects me to send:

{0xB0, 0x1E, 0x04, 0x00}

Google claims that the Hex for 270000 is 0x41EB0

So My question is how does 0x41EB0 translate to {0xB0, 0x1E, 0x04, 0x00} and how would I create this set of 4 bytes for any other number.

union is you friend here if you want to split a long int to bytes.

Woop, Thanks so much, if it helps anyone else this seems to be a good starting point:

void loop() {

union {
   unsigned long position;
   unsigned char bytes[4];
} CurrentPosition;

CurrentPosition.position = 270000;

Serial.println (CurrentPosition.bytes[0]);
Serial.println (CurrentPosition.bytes[1]);
Serial.println (CurrentPosition.bytes[2]);
Serial.println (CurrentPosition.bytes[3]);
delay(1000);

}

As a follow-up question,

is putting the int value into an array of hex values the same as putting the hex value in?

as in if I

Serial.write(176);

will this send the same as

Serial.write(0xB0);

krishpants:
As a follow-up question,

is putting the int value into an array of hex values the same as putting the hex value in?

as in if I

Serial.write(176);

will this send the same as

Serial.write(0xB0);

Yes it is

But, 0xB0 is a code that puts a non-friendly character on the Serial Monitor. Serial Monitor is a human-friendly display unit, and it always expects characters/codes within ASCII boundary. Therefore, we have to execute the following codes to see exactly B0 on the Serial Monitor.

 byte x1 = 0xB0;
byte x2 = (x1 >> 4) + 0x37;
x1 = (x1 & 0x0F) + 0x30;
Serial.write(x2);
Serial.write(x1);

GolamMostafa:
But, 0xB0 is a code that puts a non-friendly character on the Serial Monitor. Serial Monitor is a human-friendly display unit, and it always expects characters/codes within ASCII boundary. Therefore, we have to execute the following codes to see exactly B0 on the Serial Monitor.

 byte x1 = 0xB0;

byte x2 = (x1 >> 4) + 0x37;
x1 = (x1 & 0x0F) + 0x30;
Serial.write(x2);
Serial.write(x1);

if you wanted to view it in serial monitor probably easier to use Serial.print as that would do the ASCII conversion for you!

Serial.write is useful where want to output the raw byte not the ASCII equivalent which i believe is the OP intent

Ahh that's perfect, I will probably need to do this cos some response codes from the controller (which I haven't started working on yet)

But indeed the conversion using union seems to work as expected from the controllers perspective.