Break loop on greater number then unsigned long long
By : bomini
Date : March 29 2020, 07:55 AM
Hope that helps If n is unsigned long long then n <= ULLONG_MAX is always true. If you know that revert always returns a positive number you can check if n + revert( n ) is < n (i.e., check a wrap around). Or also check that revert(n) < ULLONG_MAX  n.

How can I represent a certain number of seconds (minutes) with the type unsigned long long int in C++
By : Chau Lao De
Date : March 29 2020, 07:55 AM
Does that help What are you expecting frequency.QuadPart/1000000 to do? I think you're looking for something like this? code :
LARGE_INTEGER startTime, endTime, freq;
QueryPerformanceFrequency(&freq); // freq holds the number of ticks in 1 second.
freq.QuadPart *= 8; // and now in 8 seconds.
QueryPerformanceCounter(&startTime);
for(;;)
{
QueryPerformanceCounter(&endTime);
if((endTime.QuadPart  startTime.QuadPart) >= freq.QuadPart)
{
// 8 seconds have passed.
break;
}
// do something.
}

Get the minimum number of bytes necessary to hold a given unsigned integer
By : Deva
Date : March 29 2020, 07:55 AM
seems to work fine I need to write a series of unsigned integers to a file, each one being no greater than a limit n determined at runtime. To save space, I want to pack them in as little bytes as possible. However, I've no idea how to compute the minimum number of bytes necessary to hold them, so I only have the following, ugly solution: , You might try something along these lines (untested). code :
int GetNeededBytes(uint32_t n)
{
// Maximum number of bytes supported
int bytes = 4;
// Get mask for highest order byte
// Warning: watch for overflow here
// 4 bytes should resolve to 0xff000000
int mask = 0xff << (bytes * 8);
while (bytes > 0)
{
if (n & mask)
return bytes;
mask /= 0x100;
bytes;
}
return 0;
}

Strange behavior when attempting to obtain number of digits of unsigned long long´s maximum
By : WolfpawUK
Date : March 29 2020, 07:55 AM
help you fix your problem IIUC, the OQ wants the size needed to print the maximum values in decimal. The below works for sizes of 8 bits upto 64 bits, at least for CHAR_BIT==8 : code :
#include <stdio.h>
#include <limits.h>
#define ASCII_SIZE(s) ((3+(s) * CHAR_BIT) *4 / 13)
int main(void)
{
printf("unsigned char : %zu\n", ASCII_SIZE(sizeof(unsigned char)) );
printf("unsigned short int : %zu\n", ASCII_SIZE(sizeof(unsigned short int)) );
printf("unsigned int : %zu\n", ASCII_SIZE(sizeof(unsigned int)) );
printf("unsigned long : %zu\n", ASCII_SIZE(sizeof(unsigned long)) );
printf("unsigned long long : %zu\n", ASCII_SIZE(sizeof(unsigned long long)) );
printf(" Ding : %u\n", UINT_MAX );
printf(" Lang Ding : %lu\n", ULONG_MAX );
printf("Heel lang Ding : %llu\n", ULLONG_MAX );
return 0;
}
unsigned char : 3
unsigned short int : 5
unsigned int : 10
unsigned long : 20
unsigned long long : 20
Ding : 4294967295
Lang Ding : 18446744073709551615
Heel lang Ding : 18446744073709551615

Problem of using unsigned long long int and long long int in program to calculate power of number
By : mindleaving
Date : March 29 2020, 07:55 AM
wish of those help I have written two functions to find power of positive and negative number in c but it is not printing anything , You're not actually calling the functions: code :
if(number<0)
{
void Calculate_neg_power(number,expo);
}
else{
void Calculate_pos_power(number,expo);
}
if(number<0)
{
Calculate_neg_power(number,expo);
}
else{
Calculate_pos_power(number,expo);
}
int Driver(NUMBER,EXPO, ans);

