fork download
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <sys/time.h>
  4.  
  5. int main() {
  6. // Get current time using time()
  7. time_t raw_time;
  8. struct tm *time_info;
  9.  
  10. time(&raw_time); // Get the current time (seconds)
  11. time_info = localtime(&raw_time); // Convert it to local time
  12.  
  13. // Get the current time with gettimeofday() for more precise timing
  14. struct timeval tv;
  15. gettimeofday(&tv, NULL); // Get the time including microseconds
  16.  
  17. // Print the current date and time, and break it down
  18. printf("Current Date and Time: %s", asctime(time_info)); // Full date and time
  19.  
  20. // Print the time in seconds, milliseconds, and nanoseconds
  21. printf("Time: %ld seconds\n", tv.tv_sec); // Seconds
  22. printf("Milliseconds: %ld\n", tv.tv_usec / 1000); // Convert microseconds to milliseconds
  23. printf("Nanoseconds: %ld\n", (tv.tv_usec * 1000) % 1000000); // Convert microseconds to nanoseconds
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5280KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Current Date and Time: Fri Dec 13 12:48:43 2024
Time: 1734094123 seconds
Milliseconds: 303
Nanoseconds: 226000