

// Programul afiseaza valoarea binara a unui intereg
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisare int sub forma binar");
system("COLOR F9");
int n,i; // n:numarul de convertit
cout << "\n\tProgramul afiseaza valoarea binara a unui intereg " ;
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n;
cout << " \n\tValoarea binara afisata in ordine inversa este:\n\n\t";
if (n > 0) {
for(i=0; i < 32 ; i++) {
cout << n%2;
n = n/2;
}
}
else {
cout << "\n\n\tIntroduceti un numar pozitiv\n" << endl;
}
cin.ignore();
cin.get();
return 0;
}
|
// Programul afiseaza valoarea binara a unui intereg
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisare int sub forma binar");
system("COLOR F9");
int n,i; // number to convert to binary
char val_b[32];
cout << "\n\tProgramul afiseaza valoarea binara a unui intereg " ;
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n ;
cin.ignore();
for (i=0; i < 31; i++){
if (n%2==0)
val_b[30-i]='0';
else
val_b[30-i]='1';
n=n/2;
}
cout << "\n\t Valoarea binara este:";
for (i=0; i < 31; i++)
cout << val_b[i] ;
cin.get();
return 0;
}
|
// Programul afiseaza valoarea hexa a unui intereg
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisare int sub forma hexa");
system("COLOR F9");
int n;
cout << "\n\tProgramul afiseaza valoarea hexa a unui intereg " ;
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n;
cout << " \n\tValoarea hexa este:"<< hex << n;
cin.ignore();
cin.get();
return 0;
}
|
// Programul afiseaza valoarea hexa a unui intereg
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisare int sub forma hexa");
system("COLOR F9");
int n;
cout << "\n\tProgramul afiseaza valoarea hexa a unui intereg " ;
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n;
cout << " \n\tValoarea hexa este: "<< hex << n;
cout << " \n\tValoarea lui n este: "<< n;
cout << " \n\tValoarea zecimala este:"<< dec << n;
cin.ignore();
cin.get();
return 0;
}
|
#include "stdafx.h"
#include < iostream >
#include < string >
using namespace std;
int main(void)
{
system("TITLE Utilizare format hexa ");
system("COLOR F9");
unsigned short a = 0xFFFF; // = 1111111111111111
unsigned short b = 0x5555; // = 0101010101010101
cout <<"\n\n\t In hexa a="<< hex << a;
cout <<"\n\n\t In zecimal a="<< dec << a;
cout <<"\n\n\t In hexa b="<< hex << b;
cout <<"\n\n\t In zecimal b="<< dec << b;
cin.ignore();
cin.get();
}
|
// Conversia unui intreg intr-un sir reprezentand valoarea in diferite baze de numeratie
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisarea in diferite baze de numeratie");
system("COLOR F9");
int n;
char buffer [33];
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n;
itoa(n,buffer,10);//functia pentru conversia unui intreg intr-un sir
cout << "\n\n\tValoarea zecimala a numarului este: " << buffer;
itoa(n,buffer,2);
cout << "\n\n\tValoarea binara a numarului este: " << buffer;
itoa(n,buffer,16);
cout << "\n\n\tValoarea hexa a numarului este: " << buffer;
cin.ignore();
cin.get();
return 0;
}
|
#include "stdafx.h"
#include < iostream >
using namespace std;
static void afis_bin(unsigned int n,int nb)
{
int i=0,k=0;
char val_b[32];
if ((n > 0)&&(n <= 255))
k=8;
if ((n > 255)&&(n <= 65535))
k=16;
if ((n > 65535)&&(n <= 2147483646))
k=32;
if (nb > 0)
k=nb;
if (n > 2147483646){
k=0;
cout << "\nNumar prea mare";
}
for (i=0; i < k; i++){
if (n%2==0)
val_b[k-1-i]='0';
else
val_b[k-1-i]='1';
n=n/2;
}
// afisare binara
for (i=0; i < k; i++){
if (val_b[i]=='0')
cout << char(176) << " ";
else
cout << char(219) << " ";
}
// prompter pe prima pozitie
for (i=0;i < (2*k+1); i++){
cout<<"\b";
}
}
int main(void)
{
system("TITLE AND logic ");
system("COLOR F9");
unsigned int a,b;
cout <<"\n\n\t Introduceti numarul a:";
cin >> a;
cout <<"\n\t Introduceti numarul b:";
cin >> b;
cout<<"\n\n a:\t";
afis_bin(a,16);
cout<<"\n\n b:\t";
afis_bin(b,16);
cout<<"\n\na & b:\t";
afis_bin(a&b,16);
cin.ignore();
cin.get();
return 0;
}
|
int main(void)
{
unsigned int a,b;
cout << " \n\n\tOperatii pe biti: ";
cout <<"\n\n\t Introduceti numarul a:";
cin >> hex >> a;
cout <<"\n\t Introduceti numarul b:";
cin >> hex >> b;
cout<<"\n\n a:\t";
afis_bin(a,16);
cout<<"\n\n b:\t";
afis_bin(b,16);
cout<<"\n\na & b:\t";
afis_bin(a&b,16);
cin.ignore();
cin.get();
return 0;
}
|
int main(void)
{
system("TITLE OR logic ");
system("COLOR F9");
unsigned int a,b;
cout <<"\n\n\t Introduceti numarul a:";
cin >> a;
cout <<"\n\t Introduceti numarul b:";
cin >> b;
cout<<"\n\n a:\t";
afis_bin(a,16);
cout<<"\n\n b:\t";
afis_bin(b,16);
cout<<"\n\na | b:\t";
afis_bin(a|b,16);
cin.ignore();
cin.get();
return 0;
}
|
int main(void)
{
system("TITLE OR Exclusivelogic ");
system("COLOR F9");
unsigned int a,b;
cout <<"\n\n\t Introduceti numarul a:";
cin >> a;
cout <<"\n\t Introduceti numarul b:";
cin >> b;
cout<<"\n\n a:\t";
afis_bin(a,16);
cout<<"\n\n b:\t";
afis_bin(b,16);
cout<<"\n\na ^ b:\t";
afis_bin(a^b,16);
cin.ignore();
cin.get();
return 0;
}
|
int main(void)
{
system("TITLE NOT logic ");
system("COLOR F9");
unsigned short int a;
cout <<"\n\n\t Introduceti numarul a:";
cin >> a;
cout<<"\n\n a:\t";
afis_bin(a,16);
cout<<"\n\n ~a:\t";
afis_bin(~a & 0xFFFF,16);
cin.ignore();
cin.get();
return 0;
}
|
// Deplasare dreapta
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Deplasare dreapta");
system("COLOR F9");
cout << "\n\n\tDeplasare dreapta";
unsigned short int n=64;
int i;
cout << "\n\n\tValoarea initiala a lui n: "<< n;
n = n >> 2 ;
cout << "\n\n\tValoarea lui n dupa deplasarea cu doua pozitii dreapta: "<< n;
cin.ignore();
cin.get();
return 0;
}
|
// Programul afiseaza valoarea binara a unui intereg
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisare int sub forma binar");
system("COLOR F9");
int n;
cout << "\n\tProgramul afiseaza valoarea binara a unui intereg " ;
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n ;
cin.ignore();
cout << "\n\tValoarea binara este: : ";
for (int i=31; i>=0; i--) {
int bit = ((n>>i) & 1);
cout << bit;
}
cin.get();
return 0;
}
|
// Deplasare stanga
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Deplasare stanga");
system("COLOR F9");
cout << "\n\n\tDeplasare stanga";
unsigned short int n=7;
int i;
cout << "\n\n\tValoarea initiala a lui n: "<< n;
n = n << 2 ;
cout << "\n\n\tValoarea lui n dupa deplasarea cu doua pozitii stanga: "<< n;
cin.ignore();
cin.get();
return 0;
}
|
// Deplasare stanga repetata
#include "stdafx.h"
#include < iostream >
using namespace std;
void af_binar(unsigned int );
int main(void)
{
system("TITLE Deplasare stanga repetata");
system("COLOR F9");
cout << "\n\n\tDeplasare stanga 7 pozitii \n\n\n\t\t\t";
unsigned short int n=1;
int i;
for(i=0; i < 8; i++) {
af_binar(n);
n = n << 1 ;
}
cin.ignore();
cin.get();
return 0;
}
// Afisarea bitilor ce corespund valorii parametrului u
void af_binar(unsigned int u)
{
int j;
for (int j=7; j>=0; j--) {
int bit = ((u >> j) & 1);
cout << bit<<" ";
}
cout << "\n\t\t\t";
}
|

// Programul afiseaza valoarea hexa a unui intereg
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisare int sub forma hexa");
system("COLOR F9");
int n;
char* c_hex="0123456789ABCDEF";
cout << "\n\tProgramul afiseaza valoarea hexa a unui intereg " ;
cout << "\n\n\tIntroduceti un numar intreg: " ;
cin >> n;
cout << " \n\tValoarea hexa este:\n\n\t";
for (int i=2*sizeof(int) - 1; i>=0; i--) {
cout << c_hex[((n >> i*4) & 0xF)];
}
cin.ignore();
cin.get();
return 0;
}
|
// Afisarea setului de caractere ASCII
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Afisarea setului de caractere ASCII");
system("COLOR F9");
int i ;
cout << "\n\n\tSetul de caractere ASCII extins\n";
for(i= 0;i < 256; i++){
if ((i >0) && (i % 10 == 0)){
cout << "\n\n\tApasati tasta Enter pentru continuare ";
cin.get();
}
cout <<"\n\tCod ASCII zecimal " << dec << i <<" Hexa "<< hex << i << " Caracter " << char(i);
}
cout << "\n\n\tPentru a termina apasati tasta Enter";
cin.get();
return 0;
}
|


// Conversia unui caracter ASCII intr-o valoare de tip int
#include "stdafx.h"
#include < iostream >
using namespace std;
int main(void)
{
system("TITLE Conversia ASCII int ");
system("COLOR F9");
char car;
int val_ascii;
cout << "\n\n\tIntroduceti un caracter :";
cin.get(car);
val_ascii = static_cast< int >(car);
// Se poate atribui lui val_ascii direct car
// fara a fi nevoie de conversiastatic_cast
|
// Programul cere un sir de caractere care contine litere mari si mici.
// Converteste literele mari in litere mici si afiseaza sirul.
#include "stdafx.h"
#include < iostream >
#include < string >
using namespace std;
void conv_lit(char s[]);
int main(void)
{
system("TITLE Conversie litere mari in litere mici");
system("COLOR F9");
char s[25];
int l;
cout<<"\n\tProgramul cere un sir de caractere cu litere mari si mici";
cout<<"\n\tSe va afisa sirul convertit in litere mici";
cout<<"\n\n\tIntroduceti un sir de caractere cu \n\tformat din litere mari si mici : ";cin >> s;
conv_lit(s);
cout << "\n\n\tSirul transformat in litere mici este : " << s;
cin.ignore();
cin.get();
return 0;
}
void conv_lit(char s[25])
{
int i;
i=0;
while(s[i]!=0)
{
if( (s[i] >= 65) && (s[i] <= 90) ) s[i]=s[i]+32;
i++;
}
return;
}
|
namespace secv_dr
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static int i, w, h; // h, v dimensiunile unui dreptunghi
static System.Drawing.Graphics Desen;
static System.Drawing.SolidBrush Pensula;
static System.Drawing.Pen Creion_blu;
private void button1_Click(object sender, EventArgs e)
{
Desen = this.CreateGraphics();
Pensula = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
Creion_blu = new System.Drawing.Pen(System.Drawing.Color.Blue);
w = this.Size.Width / 60;
h = this.Size.Height / 20;
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
Desen.FillRectangle(Pensula, i, this.Size.Height/3, w,h);
if (i <= this.Size.Width - 3 * w)
{
i += 3 * w;
}
else
{
i = 2 * w;
Desen.Clear(this.BackColor);
}
}
}
}
|

namespace binar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static System.Drawing.Graphics Desen;
static System.Drawing.SolidBrush Pensula;
static System.Drawing.Pen Creion_blu;
static System.UInt32 n; // numarul ce va fi convertit in binar si afisat grafic
static int i, w, h; // h, v dimensiunile unui dreptunghi
int [ ] val_b = new int [32];
private void button1_Click(object sender, EventArgs e)
{
Desen = this.CreateGraphics();
Pensula=new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
Creion_blu=new System.Drawing.Pen(System.Drawing.Color.Blue);
Desen.Clear(this.BackColor);
w=this.Size.Width/96;
h=this.Size.Height/20;
int x = 2 * w;
i=2*w;
n=0xaaaaaaaa;
for (i=0; i < 32; i++){
if (n%2==0)
val_b[31-i]=0;
else
val_b[31-i]=1;
n=n/2;
}
for (i=0;i < 32;i++){
if (val_b[i]==1)
Desen.FillRectangle(Pensula, x, this.Size.Height/3, w,h);
else
Desen.DrawRectangle(Creion_blu, x, this.Size.Height/3, w,h);
x+=3*w;
}
}
}
}
|

namespace binar_v1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static System.UInt32 n; // numarul ce va fi convertit in binar si afisat grafic
static int i, w, h; // h, v dimensiunile unui dreptunghi
static System.Drawing.Graphics Desen;
static System.Drawing.SolidBrush Pensula;
static System.Drawing.Pen Creion_blu;
private void button1_Click(object sender, EventArgs e)
{
Desen = this.CreateGraphics();
Pensula = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
Creion_blu = new System.Drawing.Pen(System.Drawing.Color.Blue);
Desen.Clear(this.BackColor);
w = this.Size.Width / 96;
h = this.Size.Height / 20;
int x = this.Size.Width - 10 * w;
n = 0xaaaaaaaa;
for (i = 31; i >= 0; i--)
{
System.UInt32 bit = ((n >> (31 - i)) & 1);
if (bit == 1)
Desen.FillRectangle(Pensula, x, this.Size.Height / 3, w, h);
else
Desen.DrawRectangle(Creion_blu, x, this.Size.Height / 3, w, h);
x -= 3 * w;
}
}
}
}
|
namespace binar_v2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static int n; // numarul ce va fi convertit in binar si afisat grafic
static int i, w, h; // h, v dimensiunile unui dreptunghi
static System.Drawing.Graphics Desen;
static System.Drawing.SolidBrush Pensula;
static System.Drawing.Pen Creion_blu;
static System.String txt;
private void textBox1_TextChanged(object sender, EventArgs e)
{
Desen = this.CreateGraphics();
Pensula=new System.Drawing.SolidBrush(System.Drawing.Color.Blue);
Creion_blu=new System.Drawing.Pen(System.Drawing.Color.Blue);
Desen.Clear(this.BackColor);
w=this.Size.Width/30;
h=this.Size.Height/20;
if (this.textBox1.Text.Length>0){
txt=this.textBox1.Text;
char c=txt[0];
c=System.Convert.ToChar(c);
n=System.Convert.ToByte(c);
this.label2.Text=System.Convert.ToString(n);
int x=this.Size.Width-6*w;
for (i = 7; i >= 0; i--)
{
int bit = ((n >> (7 - i)) & 1);
if (bit == 1)
Desen.FillRectangle(Pensula, x, this.Size.Height / 3, w, h);
else
Desen.DrawRectangle(Creion_blu, x, this.Size.Height / 3, w, h);
x -= 3 * w;
}
}
}
}
}
|

namespace binar_v3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int i; // numarul ce va fi deplasat stanga dreapta si afisat
int n, w, h; // h, v dimensiunile unui dreptunghi
int sem;
System.Drawing.Graphics Desen;
System.Drawing.SolidBrush Pensula;
System.Drawing.Pen Creion_blu ;
private void Form1_Load(object sender, EventArgs e)
{
Desen = this.CreateGraphics();
Pensula=new System.Drawing.SolidBrush(Color.Blue);
Creion_blu=new System.Drawing.Pen(Color.Blue);
w=this.Size.Width/50;
h=this.Size.Height/20;
n=0x5555; // numarul ce va fi deplasat stanga dreapta si afisat
sem=0;
}
private void timer1_Tick(object sender, EventArgs e)
{
Desen.Clear(this.BackColor);
int x=this.Size.Width-6*w;
if (sem==0){
n=n << 1;
sem=1;
}else{
n=n >> 1;
sem=0;
}
for (i=15; i >= 0; i--){
int bit=((n >> (15-i)) & 1);
if (bit==1)
Desen.FillRectangle(Pensula, x, this.Size.Height/3, w,h);
else
Desen.DrawRectangle(Creion_blu, x, this.Size.Height/3, w,h);
x-=3*w;
}
}
}
}
|

namespace binar_v4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics zona_desen;
int x0, y0, w;
string[] nume_b = new string[16] {"b0", "b1", "b2",
"b3", "b4", "b5", "b6", "b7",
"b8", "b9", "b10","b11", "b12",
"b13", "b14","b15"};
private void afis_bin_vw(Graphics desen,int px0,int py0,int bit_w,int nr_biti,string[] nume_biti, UInt64 n)
{
System.Drawing.SolidBrush p_verde, p_rosie, p_gri;
System.Drawing.Pen creion;
System.Drawing.Font f_nina;
p_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);
p_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
p_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray);
creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2);
f_nina = new System.Drawing.Font("Nina", 10);
int x = px0 + bit_w;
int y = py0 + bit_w;
int i;
for (i = nr_biti - 1; i >= 0; i--)
{
desen.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2);
desen.DrawString(nume_biti[nr_biti - i - 1], f_nina, p_rosie, x + 2 * bit_w, y);
System.UInt64 bit = ((n >> (nr_biti - i - 1)) & 1);
if (bit == 1)
desen.FillEllipse(p_verde, x, y, bit_w, bit_w);
else
desen.FillEllipse(p_gri, x, y, bit_w, bit_w);
y += 2 * bit_w;
}
}
private void Form1_Load(object sender, EventArgs e)
{
zona_desen = this.CreateGraphics();
x0 = 10;
y0 = 0;
w = 15;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
afis_bin_vw(zona_desen, x0, y0, w, 16, nume_b, 0);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
UInt64 val = System.Convert.ToUInt64(this.numericUpDown1.Value);
afis_bin_vw(zona_desen,x0, y0, w, 16,nume_b, val);
}
}
}
|

namespace binar_v5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics zona_desen;
int x0, y0, w;
string[] nume_b = new string[16] {"b0", "b1", "b2",
"b3", "b4", "b5", "b6", "b7",
"b8", "b9", "b10","b11", "b12",
"b13", "b14","b15"};
private void afis_bin_w(Graphics desen, int px0, int py0, int bit_w, int nr_biti, string[] nume_biti, UInt64 nr)
{
System.Drawing.SolidBrush p_verde, p_rosie, p_gri;
System.Drawing.Pen creion;
System.Drawing.Font f_nina;
p_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);
p_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
p_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray);
creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2);
f_nina = new System.Drawing.Font("Nina", 10);
int x = px0 + bit_w;
int y = py0 + bit_w;
int i;
for (i = nr_biti - 1; i >= 0; i--)
{
desen.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2);
desen.DrawString(nume_biti[i], f_nina, p_rosie, x, y + 2 * bit_w);
System.UInt64 bit = ((nr >> (i)) & 1);
if (bit == 1)
desen.FillEllipse(p_verde, x, y, bit_w, bit_w);
else
desen.FillEllipse(p_gri, x, y, bit_w, bit_w);
x += 2 * bit_w;
}
}
private void Form1_Load(object sender, EventArgs e)
{
zona_desen = this.CreateGraphics();
x0 = 10;
y0 = 50;
w = 15;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
afis_bin_w(zona_desen, x0, y0, w, 16, nume_b, 0);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
UInt64 val = System.Convert.ToUInt64(this.numericUpDown1.Value);
afis_bin_w(zona_desen, x0, y0, w, 16, nume_b, val);
}
}
}
|

namespace binar_v6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics zona_desen;
int x0, y0, w;
private void afis_7seg(Graphics desen, int px0, int py0, int dig_w, int dig)
{
System.Drawing.Pen cr_verde, cr_gri;
cr_verde = new System.Drawing.Pen(System.Drawing.Color.Red, dig_w/4);
cr_gri = new System.Drawing.Pen(System.Drawing.Color.WhiteSmoke, dig_w/4);
UInt16[] digit = new UInt16[10] {123,40,93,109,46,103,119,41,127,111};
int[] px = new int[7] { px0, px0, px0, px0 + dig_w, px0, px0 + dig_w, px0 };
int[] px_f = new int[7] { px0 + dig_w, px0, px0 + dig_w, px0 + dig_w, px0, px0 + dig_w, px0 + dig_w};
int[] py = new int[7] { py0, py0, py0 + dig_w, py0, py0 + dig_w, py0 + dig_w, py0 + 2 * dig_w };
int[] py_f = new int[7] { py0, py0 + dig_w, py0 + dig_w, py0 + dig_w, py0 + 2 * dig_w, py0 + 2 * dig_w, py0 + 2 * dig_w };
UInt16 nr = digit[dig];
int i;
// sterg digit
for (i = 6; i >= 0; i--)
desen.DrawLine(cr_gri, px[i], py[i], px_f[i], py_f[i]);
for (i = 6; i >= 0; i--)
{
UInt16 bit = Convert.ToUInt16((nr >> (i)) & 1);
if (bit == 1)
desen.DrawLine(cr_verde,px[i],py[i],px_f[i],py_f[i]) ;
}
}
private void Form1_Load(object sender, EventArgs e)
{
zona_desen = this.CreateGraphics();
x0 = 200;
y0 = 15;
w = 20;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
afis_7seg(zona_desen, x0, y0, w, 0);
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
int val = System.Convert.ToUInt16(Convert.ToInt16(this.numericUpDown1.Value));
afis_7seg(zona_desen, x0, y0, w, val);
}
}
}
|

namespace bin_int_v0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int nr;
private void afis_int()
{
nr=0;
if (this.checkBox1.Text == "1")
nr = nr + 1;
if (this.checkBox2.Text == "1")
nr = nr + 2;
if (this.checkBox3.Text == "1")
nr = nr + 4;
if (this.checkBox4.Text == "1")
nr = nr + 8;
if (this.checkBox5.Text == "1")
nr = nr + 16;
if (this.checkBox6.Text == "1")
nr = nr + 32;
if (this.checkBox7.Text == "1")
nr = nr + 64;
if (this.checkBox8.Text == "1")
nr = nr + 128;
this.label1.Text = nr.ToString();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox1.Text == "0")
this.checkBox1.Text = "1";
else
this.checkBox1.Text = "0";
afis_int();
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if(this.checkBox2.Text == "0")
this.checkBox2.Text = "1";
else
this.checkBox2.Text = "0";
afis_int();
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox3.Text == "0")
this.checkBox3.Text = "1";
else
this.checkBox3.Text = "0";
afis_int();
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox4.Text == "0")
this.checkBox4.Text = "1";
else
this.checkBox4.Text = "0";
afis_int();
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox5.Text == "0")
this.checkBox5.Text = "1";
else
this.checkBox5.Text = "0";
afis_int();
}
private void checkBox6_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox6.Text == "0")
this.checkBox6.Text = "1";
else
this.checkBox6.Text = "0";
afis_int();
}
private void checkBox7_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox7.Text == "0")
this.checkBox7.Text = "1";
else
this.checkBox7.Text = "0";
afis_int();
}
private void checkBox8_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox8.Text == "0")
this.checkBox8.Text = "1";
else
this.checkBox8.Text = "0";
afis_int();
}
}
}
|

namespace bin_bin_v0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics zona_desen;
int x0, y0, w;
const int nr_b = 8;
string[] nume_b = new string[] {"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7"};
bool[] val_bin = new bool[nr_b];
private void afis_bin_bin_w(Graphics desen, int px0, int py0, int bit_w, int nr_biti, bool[] vector_binar, string[] nume_biti)
{
System.Drawing.Pen creion;
System.Drawing.SolidBrush pens_verde;
System.Drawing.SolidBrush pens_rosie;
System.Drawing.SolidBrush pens_gri;
System.Drawing.Font font_nina;
creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2);
pens_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);
pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray);
font_nina = new System.Drawing.Font("Nina", 12);
int x = px0 + bit_w;
int y = py0 + bit_w;
int i;
for (i = nr_biti - 1; i >= 0; i--)
{
desen.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2);
desen.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x, y - 2 * bit_w);
if (vector_binar[i])
desen.FillEllipse(pens_verde, x, y, bit_w, bit_w);
else
desen.FillEllipse(pens_gri, x, y, bit_w, bit_w);
x += 2 * bit_w;
}
}
private void Form1_Load(object sender, EventArgs e)
{
zona_desen = this.CreateGraphics();
x0 = 7;
y0 = 100;
w = 18;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.checkBox1.Checked)
val_bin[0]=true;
else
val_bin[0] = false;
if (this.checkBox2.Checked)
val_bin[1] = true;
else
val_bin[1] = false;
if (this.checkBox3.Checked)
val_bin[2] = true;
else
val_bin[2] = false;
if (this.checkBox4.Checked)
val_bin[3] = true;
else
val_bin[3] = false;
if (this.checkBox5.Checked)
val_bin[4] = true;
else
val_bin[4] = false;
if (this.checkBox6.Checked)
val_bin[5] = true;
else
val_bin[5] = false;
if (this.checkBox7.Checked)
val_bin[6] = true;
else
val_bin[6] = false;
if (this.checkBox8.Checked)
val_bin[7] = true;
else
val_bin[7] = false;
//afis_bin(x0, y0, w, nr_b, val_bin);
afis_bin_bin_w(zona_desen, x0, y0, w, nr_b, val_bin, nume_b);
}
}
}
|

namespace si
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
Boolean a, b;
a=System.Convert.ToBoolean(this.numericUpDown1.Value);
b=System.Convert.ToBoolean(this.numericUpDown2.Value);
this.label1.Text = System.Convert.ToString(System.Convert.ToInt32(a && b));
this.label2.Text = System.Convert.ToString(a && b);
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
Boolean a, b;
a = System.Convert.ToBoolean(this.numericUpDown1.Value);
b = System.Convert.ToBoolean(this.numericUpDown2.Value);
this.label1.Text = System.Convert.ToString(System.Convert.ToInt32(a && b));
this.label2.Text = System.Convert.ToString(a && b);
}
}
}
|

namespace bin_int_v1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics zona_desen;
int x0, y0, w;
int nr_a = 0, nr_b = 0, nr_c = 0;
UInt64 nr;
string[] nume_b = new string[] {"c 0", "c 1", "c 2", "c 3", "c 4", "c 5", "c 6", "c 7"};
private void afis_bin_w(Graphics desen, int px0, int py0, int bit_w, int nr_biti, string[] nume_biti, UInt64 nr)
{
System.Drawing.SolidBrush p_verde, p_rosie, p_gri;
System.Drawing.Pen creion;
System.Drawing.Font f_nina;
p_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);
p_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
p_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray);
creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2);
f_nina = new System.Drawing.Font("Nina", 10);
int x = px0 + bit_w;
int y = py0 + bit_w;
int i;
for (i = nr_biti - 1; i >= 0; i--)
{
desen.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2);
desen.DrawString(nume_biti[i], f_nina, p_rosie, x, y + 2 * bit_w);
System.UInt64 bit = ((nr >> (i)) & 1);
if (bit == 1)
desen.FillEllipse(p_verde, x, y, bit_w, bit_w);
else
desen.FillEllipse(p_gri, x, y, bit_w, bit_w);
x += 2 * bit_w;
}
}
private void Form1_Load(object sender, EventArgs e)
{
zona_desen = this.CreateGraphics();
x0 = 7;
y0 = 100;
w = 18;
}
private void timer1_Tick(object sender, EventArgs e)
{
nr_a=0;
if (this.checkBox1.Checked)
nr_a = nr_a + 1;
if (this.checkBox2.Checked)
nr_a = nr_a + 2;
if (this.checkBox3.Checked)
nr_a = nr_a + 4;
if (this.checkBox4.Checked)
nr_a = nr_a + 8;
if (this.checkBox5.Checked)
nr_a = nr_a + 16;
if (this.checkBox6.Checked)
nr_a = nr_a + 32;
if (this.checkBox7.Checked)
nr_a = nr_a + 64;
if (this.checkBox8.Checked)
nr_a = nr_a + 128;
this.label1.Text = nr_a.ToString();
nr_b = 0;
if (this.checkBox9.Checked)
nr_b = nr_b + 1;
if (this.checkBox10.Checked)
nr_b = nr_b + 2;
if (this.checkBox11.Checked)
nr_b = nr_b + 4;
if (this.checkBox12.Checked)
nr_b = nr_b + 8;
if (this.checkBox13.Checked)
nr_b = nr_b + 16;
if (this.checkBox14.Checked)
nr_b = nr_b + 32;
if (this.checkBox15.Checked)
nr_b = nr_b + 64;
if (this.checkBox16.Checked)
nr_b = nr_b + 128;
this.label2.Text = nr_b.ToString();
if(this.radioButton1.Checked)
nr_c = nr_a & nr_b;
if (this.radioButton2.Checked)
nr_c = nr_a | nr_b;
if (this.radioButton3.Checked)
nr_c = nr_a ^ nr_b;
this.label3.Text = nr_c.ToString();
nr = Convert.ToUInt64(nr_c);
afis_bin_w(zona_desen, x0, y0, w, 8, nume_b, nr);
}
}
}
|

namespace aplic_bin_v0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Drawing.Graphics zona_desen;
System.Drawing.SolidBrush pens_rosie;
System.Drawing.Font font_nina;
int i, x0, y0, w, contor_sp = 0, faza = 0;
const int nr_in = 5; //numarul intrari (butoane, contacte)
// numele intrarilor
string[] nume_in = new string[] {"Start", "Stare cuva", "Nivel apa corespunzator",
"Temperatura apa corespunzatoare", "Golire completa"};
const int nr_out = 6; //Numarul de iesiri (actionari)
//UInt64 val;
// numele Iesirilor
string[] nume_out = new string[] {"Ventil alimentare apa", "Incalzire apa", "Spalare",
"Ventil golire apa", "Centrifugare", "Blocare cuva"};
// Afisarea iesirilor sub forma de led-uri
bool[] leduri = new bool[nr_out];
private void afis_bin_bin_vw(Graphics desen, int px0, int py0, int bit_w, int nr_biti, bool[] vector_binar, string[] nume_biti)
{
System.Drawing.Pen creion;
System.Drawing.SolidBrush pens_verde;
System.Drawing.SolidBrush pens_rosie;
System.Drawing.SolidBrush pens_gri;
System.Drawing.Font font_nina;
creion = new System.Drawing.Pen(System.Drawing.Color.Gray, 2);
pens_verde = new System.Drawing.SolidBrush(System.Drawing.Color.Lime);
pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
pens_gri = new System.Drawing.SolidBrush(System.Drawing.Color.LightGray);
font_nina = new System.Drawing.Font("Nina", 10);
int x = px0 + bit_w;
int y = py0 + bit_w;
int i;
for (i = nr_biti - 1; i >= 0; i--)
{
desen.DrawEllipse(creion, x - 1, y - 1, bit_w + 2, bit_w + 2);
desen.DrawString(nume_biti[i].ToString(), font_nina, pens_rosie, x + 2 * bit_w, y );
if (vector_binar[i])
desen.FillEllipse(pens_verde, x, y, bit_w, bit_w);
else
desen.FillEllipse(pens_gri, x, y, bit_w, bit_w);
y += 2 * bit_w;
}
}
private void Form1_Load(object sender, EventArgs e)
{
x0 = 280;
y0 = 0;
w = 15;
for (i = nr_out - 1; i >= 0; i--)
{
leduri[i] = false;
}
this.checkBox1.Checked = false;
this.checkBox1.Text = "0";
this.checkBox2.Checked = false;
this.checkBox2.Text = "0";
this.checkBox3.Checked = false;
this.checkBox3.Text = "0";
this.checkBox4.Checked = false;
this.checkBox4.Text = "0";
this.checkBox5.Checked = false;
this.checkBox5.Text = "0";
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
zona_desen = this.CreateGraphics();
pens_rosie = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
font_nina = new System.Drawing.Font("Nina", 10);
i = 0;
int y = 10;
for (i = 0; i < nr_in; i++)
{
zona_desen.DrawString(nume_in[i], font_nina, pens_rosie, 50, y);
y += 30;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
//zona_desen.Clear(this.BackColor);
afis_bin_bin_vw(zona_desen, x0, y0, w, nr_out, leduri,nume_out);
if (this.checkBox1.Checked) // Start
{
this.checkBox1.Text = "1";
if (this.checkBox2.Checked)// Cuva
{
this.checkBox2.Text = "1";
leduri[5] = true;
this.checkBox2.Enabled = false;
if (faza == 0)
{
this.label1.Text = "Masina porinita";
leduri[0] = true;// Ventil apa
}
if (this.checkBox3.Checked) // Nivel apa
{
this.checkBox3.Text = "1";
leduri[0] = false;// Ventil apa
leduri[1] = true;// Incalzire apa
if (this.checkBox4.Checked) // Temperatura corespunzatoare
{
this.checkBox4.Text = "1";
leduri[1] = false;// Incalzire apa
if (faza == 0)
{
this.label1.Text = "Spalare:";
leduri[2] = true;// Spalare
contor_sp = 100;
faza = 1;
}
}
}
}
else
{
this.label1.Text = "Cuva deschisa";
}
}
else
{
this.label1.Text = "Masina oprita";
leduri[0] = false;
leduri[1] = false;
leduri[2] = false;
leduri[3] = false;
leduri[4] = false;
}
if ((contor_sp == 0) && (faza == 1))
{
leduri[2] = false;// Spalare
this.label1.Text = "Golire apa";
leduri[3] = true;// Golire apa
faza = 2;
}
if (faza == 2)
{
if (this.checkBox5.Checked) // Golire completa
{
this.checkBox5.Text = "1";
this.label1.Text = "Centrifugare:";
leduri[3] = false;// Golire apa
leduri[4] = true;// Centrifugare
contor_sp = 50;
faza = 3;
}
}
if ((contor_sp == 0) && (faza == 3))
{
faza = 0;
leduri[0] = false;
leduri[1] = false;
leduri[2] = false;
leduri[3] = false;
leduri[4] = false;
leduri[5] = false;
this.checkBox2.Enabled = true;
this.checkBox1.Checked = false;
this.checkBox1.Text = "0";
this.checkBox2.Checked = false;
this.checkBox2.Text = "0";
this.checkBox3.Checked = false;
this.checkBox3.Text = "0";
this.checkBox4.Checked = false;
this.checkBox4.Text = "0";
this.checkBox5.Checked = false;
this.checkBox5.Text = "0";
this.label1.Text = "Gata spalare";
}
if (contor_sp > 0)
contor_sp--;
this.label2.Text = contor_sp.ToString();
this.label3.Text = "Faza: "+faza.ToString();
}
}
}
|

|
|