Binary Number in C#

step 1: Syntax While Loop

  1. While (condition)  
  2. {  
  3.    //Execute Statament  
  4. }  
step 2: Logic Binary Number

  1. protected void Button1_Click(object sender, EventArgs e)  
  2. {  
  3.     int intNo = Convert.ToInt32(txtNo.Text.Trim());  
  4.     int intBinary;  
  5.     string strBinary = "";  
  6.     while (intNo != 0)   
  7.     {  
  8.         intBinary = intNo % 2;  
  9.         intNo = intNo / 2;  
  10.         strBinary = intBinary + strBinary;  
  11.     }  
  12.     //strBinary.Reverse();  
  13.     lblBinaryNo.Text = strBinary;  
  14. }  

You can implement while loop concept and modulo and division operation easily.

Ebook Download
View all
Learn
View all