stev
stev

Reputation: 93

Powershell: how to intialize an array of bytes like in C?

In C you can do something like:

uint16_t datalen = 1024;
uint16_t crc = 0x1021;
uint8_t myHeader = {0x41, 0xBE, 0x21, 0x08, datlen/256, datalen%256, crc/256, crc%256};

Now, how can I accomplish an array initialization like this in Powershell?

I want to send the byte array later to serial port.

Upvotes: 0

Views: 716

Answers (1)

Theo
Theo

Reputation: 61068

Not so different:

[uint16]$datalen = 1024
[uint16]$crc = 0x1021
[byte[]]$myHeader = 0x41, 0xBE, 0x21, 0x08, ($datalen/256), ($datalen%256), ($crc/256), ($crc%256)

Upvotes: 2

Related Questions