0% found this document useful (0 votes)
32 views

Tema1 1) : Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

The document contains 4 code examples that demonstrate bitwise operations on bytes in C#: 1) A method that multiplies two integers, adds a constant, and multiples the result by another constant. 2) A method that sets individual bits of a byte to 1 without using functions. 3) A method that clears all but the lowest 5 bits of a byte. 4) A method that toggles (xor) individual bits of a byte.

Uploaded by

lanuse
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Tema1 1) : Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

The document contains 4 code examples that demonstrate bitwise operations on bytes in C#: 1) A method that multiplies two integers, adds a constant, and multiples the result by another constant. 2) A method that sets individual bits of a byte to 1 without using functions. 3) A method that clears all but the lowest 5 bits of a byte. 4) A method that toggles (xor) individual bits of a byte.

Uploaded by

lanuse
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Tema1 1)

using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } Int16 A, B,resultado; private void button1_Click(object sender, EventArgs e) { A = Int16.Parse(textBox1.Text); B = Int16.Parse(textBox2.Text); resultado = Operacion(A, B); textBox3.Text = Convert.ToString(resultado); } Int16 Operacion(Int16 A, Int16 B) { resultado = Convert.ToInt16(A * B); resultado = Convert.ToInt16((resultado + 2) * 5); return resultado; } } }

2) Sin funciones
using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq;

using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { byte A; A = byte.Parse(textBox1.Text); textBox2.Text = Convert.ToString(A, 2); while (textBox2.Text.Length != 8) { textBox2.Text = "0" + textBox2.Text; } A |= 0x01; A |= 0x02; A |= 0x10; A |= 0x20; A |= 0x40; A |= 0x80; textBox2.Text = Convert.ToString(A, 2); } } } 2) using using using using using using using using

System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { byte dato; dato = Convert.ToByte(textBox1.Text); dato = seteo(dato); textBox2.Text = Convert.ToString(dato); } byte seteo(byte dato) { dato = Convert.ToByte(dato | 243); return dato;

} } } 3) using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { byte A; A = byte.Parse(textBox1.Text); textBox1.Text=Convert.ToString(A,2); while(textBox2.Text.Length!=8) { textBox2.Text="0" + textBox2.Text; } A &= 0x1f; textBox3.Text = Convert.ToString(A, 2); } } }

4)
using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms;

namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } byte A; private void button1_Click(object sender, EventArgs e)

{ A = byte.Parse(textBox1.Text); textBox2.Text = Convert.ToString(A, 2); while (textBox2.Text.Length != 8) { textBox2.Text = "0" + textBox2.Text; } A ^= 0x01; A ^= 0x02; A ^= 0x40; A ^= 0x80; textBox3.Text = Convert.ToString(A, 2); } } }

You might also like