-1

Possible Duplicate:
How to get the value of individual bytes of a variable?

How can I get single bytes from a word (for example an unsigned int in C) without using bit-wise operations (that is using arithmetic operations?)

I don't know why, but this formula (C-Like) for an x number doesn't seem to work:

floor(x / pow(R, i)) % R

where R is the radix with which the number is represented, and i is used to indicate the i-th byte to obtain.

Community
  • 1
  • 1
  • 2
    Any particular reason why you don't want to use bitwise operators? – Corbin May 21 '12 at 19:56
  • 8
    This is your 6th question. You have accepted no answers and never voted. Please read the [faq] and make an effort to give back to the community from which you ask for help. – David Heffernan May 21 '12 at 19:57

1 Answers1

1

If you really need to avoid bitwise operations, you can cheat alternatively (beware if you're using a little or big endian machine!):

char *int_16_storage;
uint16_t the_word = 0xabcd;
int_16_storage = &the_word;

uint8_t low_byte = int_16_storage[0];
uint8_t high_byte = int_16_storage[1];