#cs -----------------------------------------------------------------------------------------------
_PDU_ASCII_7bit($Text) - Кодирует
_PDU_7bit_ASCII($PDU) - Декодирует
#ce -----------------------------------------------------------------------------------------------
;~ ================================================================================================
;~ ================================================================================================
Func _PDU_ASCII_7bit($s) ;Кодирует
Local $bin_long, $Result
While $s
$bin_long &= __Dec2Bin(Asc(StringRight($s, 1)))
$s = StringTrimRight($s, 1)
WEnd
While $bin_long > 0 ;Это важно
$Result &= __BinToHex(StringRight($bin_long, 8))
$bin_long = StringTrimRight($bin_long, 8)
WEnd
Return $Result
EndFunc ;==>_PDU_ASCII_7bit
;~ ================================================================================================
;~ ================================================================================================
Func _PDU_7bit_ASCII($s) ;Декодирует
Local $bin_long, $Result
While $s
$bin_long &= StringFormat('%08s', __Dec2Bin(Dec(StringRight($s, 2))))
$s = StringTrimRight($s, 2)
WEnd
While $bin_long > 0 ;Это важно
$Result &= Chr("0x" & __BinToHex(StringRight($bin_long, 7)))
$bin_long = StringTrimRight($bin_long, 7)
WEnd
Return $Result
EndFunc ;==>_PDU_7bit_ASCII
;~ ================================================================================================
;~ ================================================================================================
;~ ================================================================================================
Func __Dec2Bin($decimal)
Local $binary
While $decimal > 0
$binary = String(Mod($decimal, 2)) & $binary
$decimal = Int($decimal / 2)
WEnd
Return $binary
EndFunc ;==>__Dec2Bin
Func __BinToHex($Bin)
Local $b, $c, $d, $e, $Result
$b = StringLen($Bin)
For $i = 1 To $b
$c = StringMid($Bin, $i, 1)
$d = $b - $i
$e = $c * (2 ^ $d)
$Result = $Result + $e
Next
$Result = Hex($Result, 2)
Return $Result
EndFunc ;==>__BinToHex
;~ ================================================================================================