输入HEX作为字符串 [英] Input HEX as a string
问题描述
如何将十六进制数的字符串视为十六进制数?例如,我正在加载一个十六进制数的文件,但是Python正在以字符串形式加载该文件.能否使Powershell将文件中的十六进制数视为十六进制数?
How can I treat a string which is a hexadecimal number as a hexadecimal number? For example, I am loading in a file of hexadecimal numbers but Python is loading the file in as a string. Is it possible to get Powershell to treat the hexadecimal numbers in the file as hexadecimal numbers?
背景:我要求用户提供Mac地址,我需要在最后一个块中添加x个数字,以获取下一个x Mac地址.我可以在:"上分割并获取最后一个块,但这是一个包含例如"13"的字符串,该字符串不是十进制的13而是十六进制的13.
Background: I'm asking the user for a Mac Address and I need to add x numbers to the last block to get the next x Mac addresses. I can split on ":" and get the last block but this is a string containing for example "13", which is not 13 decimal but 13 hex.
推荐答案
通过执行以下操作解决了该问题:
Solved it by doing it like this:
$MacNr = ([int64]"0x$($MacAddress.Split(":")[5])")
$MacNr ++1
$NewMac = ('{0:X2}' -f $MacNr)
这篇关于输入HEX作为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!