You're here: Snippet Directory » Microsoft .NET » C# (33)
Language:

Dezimal2Binär

Language: Deutsch
Programming Language: C#
Published by: Cyron
Last Update: 6/22/2006
Views: 684


Description

Einfache Methode die einen Bytewert in einen 8-Bit-String umwandelt.

Code

1 //Konvertiert Dezimal nach Binär 2 private byte[] bitwert = { 128, 64, 32, 16, 8, 4, 2, 1 }; 3 private byte[] bits = new byte[8]; 4 public string dec2bin(byte Bytewert) 5 { 6 string bitstring = string.Empty; 7 for(int Counter = 0; Counter < 8; Counter++) 8 { 9 if(Bytewert >= bitwert[Counter]) 10 { 11 bits[Counter] = 1; 12 Bytewert -= bitwert[Counter]; 13 } 14 bitstring += Convert.ToString(bits[Counter]); 15 } 16 return bitstring; 17 }

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS