Hi all - its late and I really cannot figure this out!
if unsigned char *s = 42006f, how can I split/select the hex value into its pairs i.e 42/00/6f so that I can manipulate the pair data rather than the large total
using portable ansi c.
thanks!!
Hi all - its late and I really cannot figure this out!
if unsigned char *s = 42006f, how can I split/select the hex value into its pairs i.e 42/00/6f so that I can manipulate the pair data rather than the large total
using portable ansi c.
thanks!!
I'm not sure to understand what you ask.
Generally you're expected to post some code showing you've done some work, but you're right, it's late.
If this is what you want, you can guess v3, the 3rd byte (0x42).Code:#include <stdio.h> int main(void) { size_t v = 0x42006f; size_t v1 = v & 0xFF; size_t v2 = (v >> 8) & 0xFF; fprintf(stderr, "v=%#zx v1=%#zx v2=%#zx\n", v, v1, v2); return 0; }
Looks right in your example - ill give that a shot tomorrow, goodnight! and thanks
hmmm doesn't seem to work I'm afraid. I'll provide some pseudo - probably best!
v = s; /*S being the variable scanned in from user, for example 42006f*/
/*The next bit I don't know how to do, but I know what I want out of it*/
v1 = 42;
v2 = 00;
v3 = 6f
Thanks!
root4 gave you the code to split the int into bytes. It's your job to find out how to put them into the order that you think is right.hmmm doesn't seem to work I'm afraid.
Just to say it doesn't work is not enough.
Show what you tried and explain why you think it's not right.
Kurt
Actually no, what's probably best is for you to post code and show us you've actually took steps towards solving your problem.
A quick check on your posts shows the majority of them related to this same problem. If you're a beginner you should be learing the language properly and from the beginning so you can understand how to actually solve your problem, and at least learn how to ask and present your problem so the board members can help you. And if this is homework related...well we have a a policy for that In fact, I'd suggest you read the announcements before continuing.
Warning: Opinions subject to change without notice
The C Library Reference Guide
Understand the fundamentals
Then have some more fun
A "union" is made for this purpose.