home *** CD-ROM | disk | FTP | other *** search
- Unit JRBIT201 ;
-
- (*╔═════════════════════════════════════════════════════════════════════════╗*)
- (*║ ║*)
- (*║ JR Unit Library - Version 2.01 - July xxrd 1988 ║*)
- (*║ ║*)
- (*║ Hex-notation and Bit manipulation functions and procedures ║*)
- (*║ ║*)
- (*╚═════════════════════════════════════════════════════════════════════════╝*)
-
- Interface
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Function _Bitnr2Byte(_bitnr : Integer) : Byte ;
- Function _Bit(_byte : Byte ; _bitnr : Integer) : Boolean ;
- Procedure _SetBit(Var _byte : Byte ; _bitnr : Integer) ;
- Procedure _ResetBit(Var _byte : Byte ; _bitnr : Integer) ;
- Procedure _ChangeBit(Var _byte : Byte ; _bitnr : Integer) ;
- Function _Byte2Hex(_byte : Byte) : String ;
- Function _Int2Hex(_integer : Integer) : String ;
- Function _Byte2Bin(_byte : Byte) : String ;
- Function _Int2Bin(_integer : Integer) : String ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Implementation
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
-
- Function _Bitnr2Byte ;
- (* Version 1.01 *)
- (* Modified 1.02 *)
- Const _byte : Array(.0..7.) Of Byte = ($01,$02,$04,$08,$10,$20,$40,$80) ;
- Begin ;
- _Bitnr2Byte:=_byte(._bitnr.) ;
- End (* Function _Bitnr2Byte *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Function _Bit ;
- (* Version 1.00 *)
- (* Modified 2.00 *)
- Const _b : Array(.0..7.) Of Byte = ($01,$02,$04,$08,$10,$20,$40,$80) ;
- Begin ;
- _Bit:=((_byte And _b(._bitnr.))=_b(._bitnr.)) ;
- End (* Function _Bit *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Procedure _SetBit ;
- (* Version 1.01 *)
- Begin ;
- _byte:=_byte Or _Bitnr2Byte(_bitnr) ;
- End (* Procedure _SetByte *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Procedure _ResetBit ;
- (* Version 1.01 *)
- Begin ;
- _byte:=_byte And (Not _Bitnr2Byte(_bitnr)) ;
- End (* Procedure _ResetByte *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Procedure _ChangeBit ;
- (* Version 1.01 *)
- Begin ;
- _byte:=_byte Xor _Bitnr2Byte(_bitnr) ;
- End (* Procedure _ChangeBit *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Function _Byte2Hex ;
- (* Version 1.01 *)
- Const _HexDigit : Array(.0..15.) Of Char = '0123456789ABCDEF' ;
- Begin ;
- _Byte2Hex:=_HexDigit(._byte Div 16.)+_HexDigit(._byte Mod 16.) ;
- End (* Function _Byte2Hex *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Function _Int2Hex ;
- (* Version 1.01 *)
- Begin ;
- _Int2Hex:=_Byte2Hex(Hi(_integer))+_Byte2Hex(Lo(_integer)) ;
- End (* Function _Int2Hex *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Function _Byte2Bin ;
- (* Version 1.02 *)
- Var _i : Integer ;
- _temp : String ;
- Begin ;
- _temp:='' ;
- For _i:=7 DownTo 0 Do
- If _Bit(_byte,_i) Then _temp:=_temp+'1' Else _temp:=_temp+'0' ;
- _Byte2Bin:=_temp ;
- End (* Function _Int2Hex *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- Function _Int2Bin ;
- (* Version 1.02 *)
- Begin ;
- _Int2Bin:=_Byte2Bin(Hi(_integer))+_Byte2Bin(Lo(_integer)) ;
- End (* Function _Int2Hex *) ;
-
- (*───────────────────────────────────────────────────────────────────────────*)
-
- End (* Of Unit JRBIT201 *).
-