Hello everybody, With a Dtrace script I obtain for example this value: 0x1c620000 do somebody know how to cut this value in the number of octets I want and keep the value of each part in Dtrace? for example: we know that 0x1c620000 = 00011100011000100000000000000000 and I want to extract the 5 first octets, the 6 next octets, ect..: 0x1c620000 = 00011 100011 00010 0000000000000000 3 35 2 Thank you!! I hope it''s not too difficult... Fabien. -- This message posted from opensolaris.org
Hi! D supports all the same integer operators as C, so you could do this with bitwise operators, arithmetically, or theoretically with bit unions (although I''ve had trouble with bit unions in D aligning incorrectly). Here a way to do it with bitwise operators: BEGIN { i = 0x1c620000; b1 = (i >> 16) & 0x1f; b2 = (i >> 21) & 0x3f; b3 = (i >> 27) & 0x1f; printf ("%d %d %d\n", b3, b2, b1); exit (0); } Chip Lafontaine wrote:> Hello everybody, > With a Dtrace script I obtain for example this value: 0x1c620000 > do somebody know how to cut this value in the number of octets I want and keep the value of each part in Dtrace? for example: > > we know that 0x1c620000 = 00011100011000100000000000000000 > and I want to extract the 5 first octets, the 6 next octets, ect..: > 0x1c620000 = 00011 100011 00010 0000000000000000 > 3 35 2 > > Thank you!! I hope it''s not too difficult... > > Fabien. > -- > This message posted from opensolaris.org > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org >
(and, btw, those aren''t octets, those are bits...but, same thing applies. Octet specifically means ''group of 8 bits''.) Chip Bennett wrote:> Hi! > > D supports all the same integer operators as C, so you could do this > with bitwise operators, arithmetically, or theoretically with bit unions > (although I''ve had trouble with bit unions in D aligning incorrectly). > > Here a way to do it with bitwise operators: > > BEGIN > { > i = 0x1c620000; > b1 = (i >> 16) & 0x1f; > b2 = (i >> 21) & 0x3f; > b3 = (i >> 27) & 0x1f; > printf ("%d %d %d\n", b3, b2, b1); > exit (0); > } > > Chip > > Lafontaine wrote: >> Hello everybody, >> With a Dtrace script I obtain for example this value: 0x1c620000 do >> somebody know how to cut this value in the number of octets I want and >> keep the value of each part in Dtrace? for example: >> >> we know that 0x1c620000 = 00011100011000100000000000000000 >> and I want to extract the 5 first octets, the 6 next octets, ect..: >> 0x1c620000 = 00011 100011 00010 0000000000000000 >> 3 35 2 >> Thank you!! I hope it''s not too difficult... >> >> Fabien. >> -- >> This message posted from opensolaris.org >> _______________________________________________ >> dtrace-discuss mailing list >> dtrace-discuss at opensolaris.org >> > > _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org