How to get the lower 8 bits of an int in C#

1 Answer

0 votes
using System;

public class Program
{
    public static void Main()
    {
        int n = 1957;

        Console.WriteLine(Convert.ToString(n, 2).PadLeft(16, '0'));

        int low8bits = (int)(n & 0xFF);
        
        Console.WriteLine(Convert.ToString(low8bits, 2).PadLeft(16, '0'));    
    }
}




/*
run:
 
0000011110100101
0000000010100101
  
*/

 



answered Apr 3, 2024 by avibootz
edited Apr 3, 2024 by avibootz
...