$b = 10 #any value can be inserted here
$c = [int] $b
$c = "{0:X}" -f $c
$c
I want to go through a txt file, line by line, and at the 5th byte of data, I want to convert it from DEC to HEX.
This is the txt file:
80 D0 00 00 30 01 53 54 4D 30 30 38 00 00 10 D4 49 59 84 DE D4
80 20 00 00 10 26 D1 EE F6 47 11 3F 87 26 D1 EE F6 47 11 3F 87
80 30 00 00 01 FF
80 FD 00 00 00
80 88 00 00 10 0D E6 5F BF 27 CD 6D 03 C3 6D 63 69 CD A8 9C 73
80 B0 00 00 01 94
80 88 00 00 10 0D E6 5F BF 27 CD 6D 03 C3 6D 63 69 CD A8 9C 73
80 32 00 00 08 00 00 00 00 00 00 00 00
So at every 5th byte (the first one is 30, second is 10, 3rd is 01, etc…) it is converted from dec to hex. So far I have this but I am having a brain fart here at the moment and cannot seem to grasp how the foreach-object loop works:
I know what this is completely wrong but I am stuck here so any help would be amazing!
$data = "C:UsersuserDesktopdummyT2Test.txt" (Get-Content $data)| foreach-object{ if($_.length[5]){ $_ = "{0:X}" -f $_ } }
Thanks!