将 SteamID 转换为 32/64 位 SteamID Swift
Convert SteamID to 32/64 bit SteamID Swift
我的 SteamID 格式为 STEAM_0:1:21643603
。
如何将其翻译成:
- Steam32ID(帐户 ID),格式为
43287207
;
- Steam64ID 格式为
76561198003552935
;
// STEAM_X:Y:Z
func convertToSteam32ID(steamString: String) -> UInt64 {
let array = steamString.componentsSeparatedByString(":")
let Y = UInt64(array[1])!
let Z = UInt64(array[2])!
return (Z << 1) | Y
}
func convertToSteam64ID(accountID accountID: UInt64) -> UInt64 {
let Universe: UInt64 = 1
let AccountType: UInt64 = 1
let Instance: UInt64 = 1
return ((Universe << 56) | (AccountType << 52) | (Instance << 32) | accountID)
}
let steam32ID = convertToSteam32ID("STEAM_0:1:21643603")
let steam64ID = convertToSteam64ID(accountID: steam32ID)
我的 SteamID 格式为 STEAM_0:1:21643603
。
如何将其翻译成:
- Steam32ID(帐户 ID),格式为
43287207
; - Steam64ID 格式为
76561198003552935
;
// STEAM_X:Y:Z
func convertToSteam32ID(steamString: String) -> UInt64 {
let array = steamString.componentsSeparatedByString(":")
let Y = UInt64(array[1])!
let Z = UInt64(array[2])!
return (Z << 1) | Y
}
func convertToSteam64ID(accountID accountID: UInt64) -> UInt64 {
let Universe: UInt64 = 1
let AccountType: UInt64 = 1
let Instance: UInt64 = 1
return ((Universe << 56) | (AccountType << 52) | (Instance << 32) | accountID)
}
let steam32ID = convertToSteam32ID("STEAM_0:1:21643603")
let steam64ID = convertToSteam64ID(accountID: steam32ID)