home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / jr_tools / jrbit201.pas next >
Encoding:
Pascal/Delphi Source File  |  1988-07-12  |  3.7 KB  |  115 lines

  1. Unit JRBIT201 ;
  2.  
  3. (*╔═════════════════════════════════════════════════════════════════════════╗*)
  4. (*║                                                                         ║*)
  5. (*║             JR Unit Library  -  Version 2.01  -  July xxrd 1988         ║*)
  6. (*║                                                                         ║*)
  7. (*║         Hex-notation and Bit manipulation functions and procedures      ║*)
  8. (*║                                                                         ║*)
  9. (*╚═════════════════════════════════════════════════════════════════════════╝*)
  10.  
  11. Interface
  12.  
  13. (*───────────────────────────────────────────────────────────────────────────*)
  14.  
  15. Function _Bitnr2Byte(_bitnr : Integer) : Byte ;
  16. Function _Bit(_byte : Byte ; _bitnr : Integer) : Boolean ;
  17. Procedure _SetBit(Var _byte : Byte ; _bitnr : Integer) ;
  18. Procedure _ResetBit(Var _byte : Byte ; _bitnr : Integer) ;
  19. Procedure _ChangeBit(Var _byte : Byte ; _bitnr : Integer) ;
  20. Function _Byte2Hex(_byte : Byte)      : String ;
  21. Function _Int2Hex(_integer : Integer) : String ;
  22. Function _Byte2Bin(_byte : Byte)      : String ;
  23. Function _Int2Bin(_integer : Integer) : String ;
  24.  
  25. (*───────────────────────────────────────────────────────────────────────────*)
  26.  
  27. Implementation
  28.  
  29. (*───────────────────────────────────────────────────────────────────────────*)
  30.  
  31.  
  32. Function _Bitnr2Byte ;
  33. (*  Version  1.01  *)
  34. (*  Modified 1.02 *)
  35. Const _byte : Array(.0..7.) Of Byte = ($01,$02,$04,$08,$10,$20,$40,$80) ;
  36. Begin ;
  37.    _Bitnr2Byte:=_byte(._bitnr.) ;
  38. End  (* Function _Bitnr2Byte *) ;
  39.  
  40. (*───────────────────────────────────────────────────────────────────────────*)
  41.  
  42. Function _Bit ;
  43. (*  Version  1.00  *)
  44. (*  Modified 2.00  *)
  45. Const _b : Array(.0..7.) Of Byte = ($01,$02,$04,$08,$10,$20,$40,$80) ;
  46. Begin ;
  47.    _Bit:=((_byte And _b(._bitnr.))=_b(._bitnr.)) ;
  48. End  (* Function _Bit *) ;
  49.  
  50. (*───────────────────────────────────────────────────────────────────────────*)
  51.  
  52. Procedure _SetBit ;
  53. (*  Version 1.01  *)
  54. Begin ;
  55.    _byte:=_byte Or _Bitnr2Byte(_bitnr) ;
  56. End  (* Procedure _SetByte *) ;
  57.  
  58. (*───────────────────────────────────────────────────────────────────────────*)
  59.  
  60. Procedure _ResetBit ;
  61. (*  Version 1.01  *)
  62. Begin ;
  63.    _byte:=_byte And (Not _Bitnr2Byte(_bitnr)) ;
  64. End  (* Procedure _ResetByte *) ;
  65.  
  66. (*───────────────────────────────────────────────────────────────────────────*)
  67.  
  68. Procedure _ChangeBit ;
  69. (*  Version 1.01  *)
  70. Begin ;
  71.    _byte:=_byte Xor _Bitnr2Byte(_bitnr) ;
  72. End  (* Procedure _ChangeBit *) ;
  73.  
  74. (*───────────────────────────────────────────────────────────────────────────*)
  75.  
  76. Function _Byte2Hex ;
  77. (*  Version 1.01  *)
  78. Const _HexDigit : Array(.0..15.) Of Char = '0123456789ABCDEF' ;
  79. Begin ;
  80.    _Byte2Hex:=_HexDigit(._byte Div 16.)+_HexDigit(._byte Mod 16.) ;
  81. End  (* Function _Byte2Hex *) ;
  82.  
  83. (*───────────────────────────────────────────────────────────────────────────*)
  84.  
  85. Function _Int2Hex ;
  86. (*  Version 1.01  *)
  87. Begin ;
  88.   _Int2Hex:=_Byte2Hex(Hi(_integer))+_Byte2Hex(Lo(_integer)) ;
  89. End  (* Function _Int2Hex *) ;
  90.  
  91. (*───────────────────────────────────────────────────────────────────────────*)
  92.  
  93. Function _Byte2Bin ;
  94. (*  Version 1.02  *)
  95. Var    _i : Integer ;
  96.     _temp : String ;
  97. Begin ;
  98.    _temp:='' ;
  99.    For _i:=7 DownTo 0 Do 
  100.        If _Bit(_byte,_i) Then _temp:=_temp+'1' Else _temp:=_temp+'0' ;
  101.    _Byte2Bin:=_temp ;
  102. End  (* Function _Int2Hex *) ;
  103.  
  104. (*───────────────────────────────────────────────────────────────────────────*)
  105.  
  106. Function _Int2Bin ;
  107. (*  Version 1.02  *)
  108. Begin ;
  109.    _Int2Bin:=_Byte2Bin(Hi(_integer))+_Byte2Bin(Lo(_integer)) ;
  110. End  (* Function _Int2Hex *) ;
  111.  
  112. (*───────────────────────────────────────────────────────────────────────────*)
  113.  
  114. End  (* Of Unit JRBIT201 *).
  115.