Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[2760] [답변] DY304173/ [델파이]binary에 어떠한 정보가 내장
grcsb [ ] 1558 읽음    1998-05-11 03:50
Unit Bit;


Interface

Function  ByteToBinary(Value:Byte):String;
Function  BinaryToByte(Value:String):Byte;
{각 Value와 같은 형태의 변수를 이진수로 표현되는 문자열로 바꿔준다.}

Implementation

Function  ByteToBinary(Value:Byte):String;
Var
   bTemp, bValue : Byte;
Begin
  Result:= '00000000';
  bTemp:= (Value shr 7);
  bValue:= Value-(bTemp shl 7);
  If bTemp = 1 then Result[1]:= '1';
  bTemp:= (bValue shr 6);
  bValue:= bValue-(bTemp shl 6);
  If bTemp = 1 then Result[2]:= '1';
  bTemp:= (bValue shr 5);
  bValue:= bValue-(bTemp shl 5);
  If bTemp = 1 then Result[3]:= '1';
  bTemp:= (bValue shr 4);
  bValue:= bValue-(bTemp shl 4);
  If bTemp = 1 then Result[4]:= '1';
  bTemp:= (bValue shr 3);
  bValue:= bValue-(bTemp shl 3);
  If bTemp = 1 then Result[5]:= '1';
  bTemp:= (bValue shr 2);
  bValue:= bValue-(bTemp shl 2);
  If bTemp = 1 then Result[6]:= '1';
  bTemp:= (bValue shr 1);
  bValue:= bValue-(bTemp shl 1);
  If bTemp = 1 then Result[7]:= '1';
  If bValue = 1 then Result[8]:= '1';
End;

Function  BinaryToByte(Value:String):Byte;
Var
   Loop : Integer;
Begin
  For Loop:= 1 to 8-Length(Value) do Value:= '0'+Value;
  Result:= Byte((Value[1] = '1')) shl 7 +
           Byte((Value[2] = '1')) shl 6 +
           Byte((Value[3] = '1')) shl 5 +
           Byte((Value[4] = '1')) shl 4 +
           Byte((Value[5] = '1')) shl 3 +
           Byte((Value[6] = '1')) shl 2 +
           Byte((Value[7] = '1')) shl 1 +
           Byte((Value[8] = '1'));
End;

End.


+ -

관련 글 리스트
2760 [답변] DY304173/ [델파이]binary에 어떠한 정보가 내장 grcsb 1558 1998/05/11
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.