For Programmers: Free Programming Magazines  


Home > Archive > Matlab > August 2007 > Hex/Binary to decimal









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Hex/Binary to decimal
Anthony

2007-08-29, 7:16 pm

Trying to read in a text file that has 16bit binary
numbers, or hex values of those 16 bits. I want to convert
these values to decimal but I want to have negative numbers
also. Is there a way to convert but to consider the sign
bit?
dpb

2007-08-30, 8:59 pm

Anthony wrote:
> Trying to read in a text file that has 16bit binary
> numbers, or hex values of those 16 bits. I want to convert
> these values to decimal but I want to have negative numbers
> also. Is there a way to convert but to consider the sign
> bit?


Try fscanf()

Otomh I don't recall whether there's a way to set the size of the data
field for interpretation w/ the '%x' format descriptor on input or not.

If that fails, guess you would have to write a function to do the
conversion from the 32-bit representation unless there are more
facilities than in the versions I'm familiar with (which are getting
more and more out of date, alas)... :(

--
Walter Roberson

2007-08-30, 8:59 pm

In article <fb4jhs$7do$1@fred.mathworks.com>,
Anthony <anthony.campos@baesystems.com> wrote:
>Trying to read in a text file that has 16bit binary
>numbers, or hex values of those 16 bits. I want to convert
>these values to decimal but I want to have negative numbers
>also. Is there a way to convert but to consider the sign
>bit?

[color=darkred]
ans =

-25045
16383


--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com