Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [SOLVED] Why long long int seems to be 32 bit longer?
[SOLVED] Why long long int seems to be 32 bit longer? [message #52144] Mon, 29 July 2019 08:19 Go to previous message
forlano is currently offline  forlano
Messages: 1213
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

perhaps this is not U++ related but it depends by some compiler flag I am not aware of (MSVC 2017).
According to wikipedia https://en.wikipedia.org/wiki/C_data_types

long long int

should be 64 bit longer. Now I want to set the bits of such number.
Here is a simple code that set the kth bit in a long long int

#include <Core/Core.h>
using namespace Upp;
#include <climits>

// set the kth bit 
long long int setKthBit(int n, int k) 
{ 
    return ((1 << k) | n); 
} 
 
int getKthBit(int n, int k)
{
  return (n & ( 1 << k )) >> k;
}

CONSOLE_APP_MAIN
{ unsigned long long  num = 0, n;
  int k = 30;
  n = setKthBit(num, k);
  printf("%llu \n", n);
  Cout()<<getKthBit(n,k);
  //Cout() << "unsigned long long max = " << ULLONG_MAX ;
}


What I observe is that for k>30 the code does not work. It seems it cannot use a proper 64 bit number.
what am I missing?

Thanks,
Luigi

[Updated on: Tue, 30 July 2019 12:12]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Problem with LanguageInfo
Next Topic: Implementation of Vector::Add()
Goto Forum:
  


Current Time: Thu Aug 21 05:32:54 CEST 2025

Total time taken to generate the page: 0.04242 seconds