Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6338383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:26:02+00:00 2026-05-24T19:26:02+00:00

Here is the code: #include <iostream> using namespace std; template<class T> void printbinary3(T num){

  • 0

Here is the code:

#include <iostream>

using namespace std;

template<class T>
void printbinary3(T num){
   for(int i = sizeof(T) * 8 - 1; i >= 0 ; --i) {
      if((1 << i) &  num)
         cout << "1";
      else
         cout << "0";   
   }
   cout << endl;
}

int main ()
{
   char a = 1;
   short b = 1;
   int c = 1;
   long d = 1;
   __int64 e = 1;
   unsigned __int64 f = 1;

   printbinary3(a);
   printbinary3(b);
   printbinary3(c);
   printbinary3(d);
   printbinary3(e);
   printbinary3(f);
   return 0;
}   

Here is the output:

00000001
0000000000000001
00000000000000000000000000000001
00000000000000000000000000000001
0000000000000000000000000000000100000000000000000000000000000001

When compiling I get this error for the unsigned __int64 variable – f.

1> : warning C4334: '<<' : result of 32-bit shift implicitly converted to 
     64 bits (was 64-bit shift intended?)
1>   xx.cpp(66) : see reference to function template instantiation 
     'void printbinary3<unsigned __int64>(T)' being compiled

Why am I not seeing

0000000000000000000000000000000000000000000000000000000000000001

as the output for the 64 bit integer?

Angus

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:26:04+00:00Added an answer on May 24, 2026 at 7:26 pm

    In your printbinary3 function:

    void printbinary3(T num){
       for(int i = sizeof(T) * 8 - 1; i >= 0 ; --i) {
          if((1 << i) &  num)
    

    Here, you are creating a literal 1 of type int, which most probably is 32 bit. If T = __int64, you will shift it for too many bits, leading to an overflow and the warning.

    Instead of using implicit int, explicitely create a T instead:

          if((T(1) << i) &  num)
    

    This should fix the warning and the output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here the code #include <iostream> #include <conio.h> using namespace std; template <typename T> class
Here is my code - #include<iostream> using namespace std; class base { public: void
code: #include<iostream> using namespace std; template<class T, int N> class point { T coordinate[N];
Please Explain the following code #include <iostream> using namespace std; int main() { const
Here's the code. Is it possible to make last line work? #include<iostream> using namespace
I tried the following program on Visual Studio 2010. #include <iostream> using namespace std;
Here is the compilable code and the problem is still there #include <iostream> #include
I'm trying a basic input,output(and append) in C++ here is my code #include <iostream>
Here's the code. Not much to it. <?php include("Spreadsheet/Excel/Writer.php"); $xls = new Spreadsheet_Excel_Writer(); $sheet
I am using pseudo-code here, but this is in JavaScript. With the most efficient

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.