C++ Variadics Hackerrank Solution in C++ | Other Concepts

C++ Variadics Hackerrank Solution in C++. A template parameter pack is a template parameter that accepts zero or more template arguments (non-types, types, or templates). To read more about the parameter packs, click here.

Create a template function named reversed_binary_value. It must take an arbitrary number of bool values as template parameters. These booleans represent binary digits in reverse order. Your function must return an integer corresponding to the binary value of the digits represented by the booleans. For example, reversed_binary_value<0,0,1>() should return 4.

C++ Variadics Hackerrank Solution in C++

Input Format

The first line contains an integer, t, the number of test cases. Each of the t subsequent lines contains a test case. A test case is described as 2 space-separated integers, x and y, respectively.

  • x is the value to compare against.
  • y represents the range to compare: 64*y to 64*y+63.


  • 0 <= x <= 65535
  • 0 <= y <= 1023
  • The number of template parameters passed to reversed_binary_value will be <= 16.

Output Format

Each line of output contains 64 binary characters (i.e., 0's and 1's). Each character represents one value in the range. The first character corresponds to the first value in the range. The last character corresponds to the last value in the range. The character is 1 if the value in the range matches X; otherwise, the character is 0.

Sample Input

65 1
10 0

Sample Output


Submit your solution here: Click here

C++ Variadics Hackerrank Solution in C++

#include <iostream>
using namespace std;

// Enter your code for reversed_binary_value < bool...>()

template < bool first, bool...digits >
	constexpr int reversed_binary_value()
		if constexpr(sizeof...(digits) > 0)
		return first + reversed_binary_value < digits... > () *2;
			return first;

template < int n, bool...digits >
	struct CheckValues
		static void check(int x, int y)
			CheckValues < n - 1, 0, digits... >::check(x, y);
			CheckValues < n - 1, 1, digits... >::check(x, y);

template < bool...digits >
	struct CheckValues<0, digits... >
		static void check(int x, int y)
			int z = reversed_binary_value < digits... > ();
			std::cout << (z + 64 *y == x);

int main()
	int t;
	std::cin >> t;

	for (int i = 0; i != t; ++i)
		int x, y;
		cin >> x >> y;
		CheckValues<6>::check(x, y);
		cout << "\n";

The Output of C++ Variadics Hackerrank Solution

The Output of C++ Variadics Hackerrank Solution

Similar to C++ Variadics

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me