How to count the number of leading zero bits in an unsigned 64-bit integer using WinForms with C#

1 Answer

0 votes
using System.Numerics;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ulong value = 25714998; // 0000 0001 1000 1000 0110 0001 0011 0110

            int LeadingZeros = BitOperations.LeadingZeroCount(value);

            MessageBox.Show(LeadingZeros.ToString());
        }
    }
}




/*
run:
 
39

*/

 



answered Apr 8, 2024 by avibootz
...