# understanding the logic of uint32 to uint8 conversion in pointers

#### yef smith

Joined Aug 2, 2020
605
Hello,In the code bellow:
regarding arr[0] if we shift its binary 24 then in hex each letter is 4 bites so 02F003E7 will be 00,00,00,02 then we do bitwise and with FF
which keep the number as 0x02

regarding arr[1] if we shift it 16 places the in hex we shift it 4 letters so Tx_PP will be 000002F0 doing bit wise and with FF will keep F0
etc..
My question is how can we implement it int * & representation, i want to jump uint8 and take 8bits,how can i do it using & *?
Thanks.
Code:
uint8_t arr[4];
uint32_t Tx_PP= 0x02F003E7;
arr[0]=(Tx_PP >> 24) & 0xFF;
arr[1]=(Tx_PP >> 16) & 0xFF;
arr[2]=(Tx_PP >> 8) & 0xFF;
arr[3]=(Tx_PP) & 0xFF;
SPI_transfer(USART1,arr);

#### nsaspook

Joined Aug 27, 2009
12,349

#### michael8

Joined Jan 11, 2015
377
Which case of SPI_transfer are you using:
https://www.arduino.cc/en/Reference/SPITransfer
 receivedVal = SPI.transfer(val) send/recieve one byte receivedVal16 = SPI.transfer16(val16) send/receive two bytes SPI.transfer(buffer, size) send/receive buffer of data (1 or more bytes...) 

> implement it int * & representation, i want to jump uint8 and take 8bits,how can i do it using & *

I don't understand what that asks.

#### yef smith

Joined Aug 2, 2020
605
I want to take uint32_t Tx_PP= 0x02F003E7 and break it into 4 parts using pointers to make an array uint8_t arr[4]
so arr[0]=Tx_PP
arr[1]=&Tx_PP+8
i am not sure

#### nsaspook

Joined Aug 27, 2009
12,349
What are you not sure about?
C:
#include <stdint.h>
#include <stdio.h>

uint8_t *arr;

uint32_t Tx_PP= 0x02F003E7;
int main(void)
{
arr=(uint8_t*) &Tx_PP;
printf("\r\n uint8_t pointer array indexing %.2x, %.2x, %2.x, %.2x \r\n",arr[0],arr[1],arr[2],arr[3]);
return 0;
}
Running on Linux.

uint8_t pointer array indexing e7, 03, f0, 02