09-06-2013 10:35 AM
Dear all,
I have a binary data set which I want to convert using negative powers of two. For example I have a binary data
11101100100000000000000
which I want to convert in decimal using method below ( negative powers of two).
(1 * 2^-1) + (1 * 2^-2) + (1 * 2^-3) + (0 * 2^-4) + ... + (0 * 2^-23).
I have been successful till the part or reversing the whole data set but couldn't figure out the rest. Help is sorely needed.
Regards.
Solved! Go to Solution.
09-06-2013 10:39 AM - edited 09-06-2013 10:44 AM
09-06-2013 10:45 AM
Dear GerdW,
Thanks alot 🙂
Regards.
09-06-2013 11:24 AM
A simpler way would be to use the Reverse String function and then use the Scan From String with the %b format.
09-06-2013 01:03 PM
Dear crossrulz,
I tried your suggestion but I wasn't getting required result. I reversed the string and fed it into the scan from string block with the %b format. I couldn't get the value as I would get by trying the above mentioned suggestion.
Or may be I didn't understand your suggestion properly.
Regards.
09-06-2013 01:20 PM
Sounds like a job for Integer to fixed point cast:
09-06-2013 02:40 PM
@NapDynamite wrote:
Dear crossrulz,
I tried your suggestion but I wasn't getting required result. I reversed the string and fed it into the scan from string block with the %b format. I couldn't get the value as I would get by trying the above mentioned suggestion.
Or may be I didn't understand your suggestion properly.
Regards.
Nope. I misinterpreted something. Sorry.
That integer to fixed point is a nice trick!
09-06-2013 05:58 PM - edited 09-06-2013 05:59 PM
That would be a Binal (or what you should call the fractional part of a binary number), so simply do binary string to number and divide by 2^string length. (which is the top part of Gerds solution ^^)
/Y
09-06-2013 06:22 PM - edited 09-06-2013 06:23 PM
@GerdW wrote:
Edit: I added one possible "hard way bit by bit" solution as well..
The hard way can be made quite a bit less hard, e.g. as follows. 😄
It is probably pretty fast (not tested, though).

09-07-2013 12:04 AM
Dear Willd,
I have a little difficulty knowing the purpose of constant defined that is connected to fixed-point type. This is the first time I'm using this function. Why do we have to change the encoding of this constant to unsigned, word length to 23 bits and integer word length to 0 bits? A little explanation would be appreciated so I could get a better understanding for problems in future.
Regards.