You're on the right track but should use bit shift operators rather
then division to get values into bytes, something like:

        a = (uint8) (uintval & 0xff000000) >> 24;

You will also need to be careful that you do all this with
unsigned ints or sprinkle "& 0xff"'s all over the place to
avoid sign extension problems.

Another perhaps easier way is to use a union like:

        union
        {
          uint32 uintval;
          uint8  bytes[sizeof uint32];
        } bunion;

which you can then use it like this:

        bunion x;
        x.uintval = 0x12345678;
        a = x.bytes[0];

But I think you may have to deal with byte ordering issues if
you go cross platform. There's another really tricky way to do
this that I have completely forgotten and the example I have
_may_ be hidden on another machine in my massively parallel
filing system...I _could_ (perhaps) find it if you really
need it...

MS


Lorena Aguirre wrote:
> Hello,
>  
> I'm trying to do a task to pass from Hex to Decimal (from uint 32 to uint8)
> I have uint32 (ABCD) and I want 4 uint8 with 'A',  another 'B', another 
> 'C' and another 'D'.
> The task I created is the following but it doesn't work, Could anyone 
> help me please?
>  
> //----------------------------task mascara
> //TAREA mascar entero 32 a entero8
>   task void mascara(){
>   t1 =  call Localizar.get();
>   tiempo2 = t1;
>   tiempo1A = tiempo1 & 0xFF000000; /* pasamos a hexadecimal*/
>   tiempo1A = tiempo1A / 0xFFFFFF;
>   tiempo1 = tiempo2;
>   tiempo1B = tiempo1 & 0xFF0000;
>   tiempo1B = tiempo1B / 0xFF00;
> 
>   tiempo1 = tiempo2;
> 
>   tiempo1C = tiempo1 & 0xFF00;
>   tiempo1C = tiempo1C / 0xFF;
>   tiempo1 = tiempo2;
>   tiempo1D = tiempo1 & 0xFF;
>  
>   }
> 
> //----------------------------in the task RadioSendTask I call task mascara 
> task void RadioSendTask() {
> 
>     dbg(DBG_USR1, "MiTOSBase forwarding UART packet to Radio\n");
> 
>     if (radioCount == 0) {
> 
>       radioBusy = FALSE;
> 
>     } else {
> 
>       radioQueueBufs[radioOut].group = 0x7D; // antes TOS_AM_GROUP
>       //este start de error. Sin arrancarlo no da errores.
>   //call Localizar.start();
>   //capturamos t1 para calculo de RTT
>   temps1 = call Localizar.get();  
>   post mascara();
>    radioQueueBufs[radioOut].data[2] = tiempo1A;
>    radioQueueBufs[radioOut].data[2] = tiempo1B;
>    radioQueueBufs[radioOut].data[2] = tiempo1C;
>    radioQueueBufs[radioOut].data[2] = tiempo1D;
>       if (call RadioSend.send(&radioQueueBufs[radioOut]) == SUCCESS) {
> call Leds.redToggle();
>       } else {
> failBlink();
> post RadioSendTask();
>       }
>     }
>   }
>  
> Thanks!
> Lorena
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

-- 
Platform: WinXP/Cygwin
TinyOS version: 1.x, Boomerang
Programmer: MIB510
Device(s): Mica2, MicaZ, Tmote
Sensor board: homebrew

_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to