VBS中的左移位&右移位运算

标签: , , , ,

之前用VBS写UTF-16编码转UTF-8编码的时候要用到移位运算,但是VBS中没有移位运算符,就用简单的乘除运算实现了移位运算函数。而移位运算并不仅仅是简单的乘除而已,这样写可能会有未知的错误。现在知道了MSScriptControl.ScriptControl对象,实现左移位、右移位是如此的简单。

Function LShift(Value, Shift)
	Set sc = CreateObject("MSScriptControl.ScriptControl")
	sc.Language = "JScript"
	LShift = sc.Eval(Value & "<<" & Shift)
End Function

Function RShift(Value, Shift)
	Set sc = CreateObject("MSScriptControl.ScriptControl")
	sc.Language = "JScript"
	RShift = sc.Eval(Value & ">>" & Shift)
End Function
赞赏

微信赞赏支付宝赞赏

随机文章:

  1. VBS技术内幕:CreateObject函数
  2. 用JavaScript实现PHP的basename函数
  3. DOSLNK.EXE下载
  4. Unable to find the socket transport "ssl" – did you forget to enable it when you configured PHP?
  5. 用VBS实现繁体中文和简体中文转换

留下回复