eolymp
bolt
Try our new interface for solving problems
Problems

Bit value

published at 3/28/18, 5:46:05 pm
  1. Число в двійковому коді має мати 32 біти
  2. Нумерація бітів справа наліво починаючи з нуля
published at 1/8/24, 3:12:39 pm

c# - 100%

using System; namespace ConsoleApp1 { internal class Program { static void Main() { string n = Console.ReadLine(); string[] arr = n.Split(' '); int a = int.Parse(arr[0]); int k = int.Parse(arr[1]); string binary = Convert.ToString(a, 2); if (k < binary.Length) Console.WriteLine(binary.Substring(binary.Length - 1 - k, 1)); else Console.WriteLine(0); Console.ReadKey(); } } }

published at 1/27/24, 1:53:20 pm

include <bits/stdc++.h>

define ll long long int

define ld long double

using namespace std; int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k, i = 0;
cin>>n>>k;
while(1){
    if(i == k){
        cout<<n%2;
        return 0;
    }
    i++;
    n/=2;
}

} //TECHNOBLADE NEVER DIES