Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace lbonarna
- {
- class binarna
- {
- string lbinarna;
- public binarna(string bin)
- {
- lbinarna = bin;
- }
- public int dziesietnie()
- {
- int dziesietna = 0;
- for (int i = 0; i < lbinarna.Length; i++)
- {
- // Console.WriteLine("Debug: {0},{1},{2}", i, dziesietna,lbinarna[i]);
- if (lbinarna[i] == '1')
- {
- dziesietna += Convert.ToInt32(Math.Pow(2, i));
- }
- }
- return dziesietna;
- }
- public string negacja()
- {
- string zanegowany = String.Empty;
- for (int i = 0; i < lbinarna.Length; i++)
- {
- if (lbinarna[i] == '1')
- {
- zanegowany += '0'; ;
- }
- else
- {
- zanegowany += '1'; ;
- }
- }
- return zanegowany;
- }
- public void drukuj()
- {
- Console.WriteLine("Postać dziesiętna:{0}", dziesietnie());
- Console.WriteLine("Postać zanegowana:{0}", negacja());
- }
- class Program
- {
- static void Main(string[] args)
- {
- string b;
- binarna liczba_b;
- Console.WriteLine("Podaj liczbę w postaci binarnej");
- b = Console.ReadLine();
- liczba_b = new binarna(b);
- liczba_b.drukuj();
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement