-6

I want to convert my timeval struct from seconds to nanoseconds, what is the best algorithm to achieve this?

ka123444
  • 15
  • 1
  • 4

1 Answers1

2

I would suggest this:

uint64_t nanosec(struct timeval t) { /* Calculate nanoseconds in a timeval structure */ 
  return t.tv_sec * 1000000000 + t.tv_usec * 1000; 
}
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
jj_3684
  • 21
  • 1