reversing bits in a truncated byte
Hi,
I have an embedded application where I read in 5 address lines (AD0-AD4) into 5 I/Os on my microcontroller, and as I seem to want to make life as hard for myself as possible I have connected AD4 to pin 0, AD3 to pin 1 etc.
This is how I obtain the address from my 16-bit wide port:
Code:
PortC_data = GPIO_ReadInputData(GPIOC);
psu_addr = (PortC_data & 0xFF) & 0x1F;
When I put in 00001, I get 0x10 instead of 0x01.
I tried doing a <<4 , but that didn't seem to work, and I have reached the end of my knowledge on bit manipulations.
Can anyone help me prevent a hardware redesign?
--dave