[prev in list] [next in list] [prev in thread] [next in thread]
List: opensolaris-dtrace-discuss
Subject: Re: [dtrace-discuss] translate byte array to uint64_t
From: Jonathan Adams <jonathan.adams () sun ! com>
Date: 2009-05-19 19:05:00
Message-ID: 20090519190500.GT163312 () eng ! sun ! com
[Download RAW message or body]
On Mon, May 18, 2009 at 04:17:16PM -0400, Priya Krishnan wrote:
> I have a translator related question, One of the members of my native
> structure is a 8-byte array. In the equivalent D struct, this member is
> represented as an uint64_t. It is preferable to convert the byte-array
> to an uint64_t in the translator. Is this possible?
Certainly:
(uint64_t)ba[0] << (64 - 0*8 - 8) +
(uint64_t)ba[1] << (64 - 1*8 - 8) +
(uint64_t)ba[2] << (64 - 2*8 - 8) +
(uint64_t)ba[3] << (64 - 3*8 - 8) +
(uint64_t)ba[4] << (64 - 4*8 - 8) +
(uint64_t)ba[5] << (64 - 5*8 - 8) +
(uint64_t)ba[6] << (64 - 6*8 - 8) +
(uint64_t)ba[7] << (64 - 7*8 - 8);
If endianess and alignment aren't an issue, you could do *(uint64_t *)ba.
Cheers,
- jonathan
> i.e. I am looking for an equivalent to the following C program
> uint64_t result = 0;
> char str[256] ;
>
> snprintf(str, 256, "%x%x%x%x%x%x%x%x",
> ba[0], ba[1], ba[2], ba[3], ba[4], ba[5], ba[6], ba[7]);
> result = strtoull((char *)ba, NULL, 16);
>
> Any suggestion is appreciated
>
> thanks
> Priya
>
>
>
>
>
>
>
> _______________________________________________
> dtrace-discuss mailing list
> dtrace-discuss@opensolaris.org
_______________________________________________
dtrace-discuss mailing list
dtrace-discuss@opensolaris.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic