|
"Wyatt" wrote in message <k7bb0o$f78$1@newscl01ah.mathworks.com>...
> "Yadunandan " <nandu@mando.com> wrote in message <jfsu4b$4b0$1@newscl01ah.mathworks.com>...
> > "David Young" wrote in message <h9b15q$mgf$1@fred.mathworks.com>...
> > > Your questions isn't entirely clear, because "hex number" and "decimal number" aren't well-defined terms. Hex is a notation for writing down or printing out a number (or representing it as a string in memory) but it isn't usually needed in the course of a computation. What I think you're asking is just how to combine two numbers that represent the 16-bit halves of a 32-bit word.
> > >
> > > If you read in the first column of your file to c1, and the second column to c2, then, if I've understood your question correctly, you can combine them just by doing:
> > >
> > > c = c1 * 65536 + c2;
> > >
> > > or, perhaps more clearly,
> > >
> > > c = bitor( bitshift(c1, 16), c2 );
> > >
> > > and not using hex at all.
> > >
> > > Hope that helps.
> >
> > I have the same problem. Thanks alot David. But, what if one of the values is negative number. In this case, could you please suggest me a solution ? It would be really helpful.
> >
> > Thank You
>
> You will need to put in a conditional statement (if/else). If the signed bit is the leftmost bit in a 16 bit string, then if your decimal value is greater than (2^15)-1 (or 32767), then the value is negative, or positive, however the signed bit works. You can then use the conditional statement to make the appropriate calculation to make your decimal value negative.
Since hex2num operates on string, then what about doing
hex2num(['4230' '2FE1'])
|