How to use bitwise or (|) in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 1;
            int b = 100;

            int or = a | b;

            Console.WriteLine(or);
        }
    }
}


/*
run:
    
101

*/

 



answered Feb 14, 2017 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 9;
            int b = 16;

            int or = a | b;

            Console.WriteLine(or);

            Console.WriteLine("a  = " + Convert.ToString(9, 2).PadLeft(8, '0'));
            Console.WriteLine("b  = " + Convert.ToString(16, 2).PadLeft(8, '0'));
            Console.WriteLine("or = " + Convert.ToString(or, 2).PadLeft(8, '0'));
        }
    }
}


/*
run:
    
25
a  = 00001001
b  = 00010000
or = 00011001

*/

 



answered Feb 14, 2017 by avibootz

Related questions

1 answer 221 views
2 answers 290 views
1 answer 177 views
1 answer 147 views
147 views asked Feb 15, 2017 by avibootz
2 answers 201 views
201 views asked Feb 14, 2017 by avibootz
2 answers 144 views
144 views asked Apr 13, 2023 by avibootz
...