を値を追加:私は最初の2桁と最後の2桁を削除したいS214FE0420FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00は、文字列をバイト配列に変換し、入力文字列がのようになり、バッチファイルで
。 次に残りの数字をペアで(16進数で)合計したいと思います。 例:14 + FE + 04 + 20 + FF + ...
これを行うにはどうすればよいでしょうか?
ありがとうございました。
を値を追加:私は最初の2桁と最後の2桁を削除したいS214FE0420FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00は、文字列をバイト配列に変換し、入力文字列がのようになり、バッチファイルで
。 次に残りの数字をペアで(16進数で)合計したいと思います。 例:14 + FE + 04 + 20 + FF + ...
これを行うにはどうすればよいでしょうか?
ありがとうございました。
私は自分で努力していませんが、簡単なスクリプトを提供することにしました。次回はあなた自身で試してみてください!だからここ
はコードが(すべての説明rem
発言を参照)である。
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem // Define constants here:
set "_STRING=S214FE0420FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00"
if not defined _STRING set /P _STRING="" & rem // (prompt if empty constant)
set "_TRUNCL=2" & rem // (truncate this many characters from the left)
set "_TRUNCR=2" & rem // (truncate this many characters from the right)
setlocal EnableDelayedExpansion
rem // Truncate defined number of characters:
set "STRING=!_STRING:~%_TRUNCL%,-%_TRUNCR%!"
rem // Initialise pointer and buffer:
set /A "POINTER=0, BUFFER=0"
rem // Skip loop if truncated string is empty:
if not defined STRING goto :NEXT
rem // Establish loop to walk through string at every two characters:
:LOOP
rem /* Prefix pointed two characters with `0x` to be interpreted as hexadecimal
rem number and add them to buffer; afterwards increment pointer by 2 + 1
rem (the additional 1 is intended to ignore the last digit if there is an
rem odd number; the 1 is subtracted later again): */
set /A "BUFFER+=0x!STRING:~%POINTER%,2!, POINTER+=3"
rem /* Check if characters are still available at the new pointer, then
rem subtract the aforementioned 1 from the new pointer: */
if not "!STRING:~%POINTER%!"=="" set /A "POINTER-=1" & goto :LOOP
rem /* No more characters are available, so leave the loop; also subtract the
rem aforementioned 1 from the new pointer, so it holds the string length: */
set /A "POINTER-=1"
rem // This is the point beyond the loop:
:NEXT
rem // Return the result:
echo/sum: %BUFFER%
echo/length: %POINTER%
endlocal
endlocal
exit /B
ここで私は何の助けを提供しないであろうために、完全に従ったうえで、注釈のない例です。
@Echo Off
SetLocal EnableDelayedExpansion
Set "input=S214FE0420FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00"
For /L %%A In (2 2 40) Do Set "output=!output!+0x!input:~%%A,2!"
Set/A output=%output:~1%
Echo(%input:~2,-2%=%output%
Timeout -1
あなたの答えは:スクリプトを書くことです。 [ツアー]を読んで[尋ねる]をお読みください! Stack Overflowは無料のコード/スクリプト作成サービスではないので、あなた自身で試してみる必要があります。スタックしてしまったら、ここに戻って特定の質問をしてください! – aschipfl
私は誰にもコードを書くように頼んだわけではありません。私は使用する最も効率的なアルゴリズムを探していました。バッチスクリプトが提供しなければならないことを私は知らないので、それは私が探しているヘルプです。 – JohnnyX
しかし、解決策を提供する時間を捧げた人々に感謝します。 – JohnnyX