Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

convert binary string into integer

Does anybody know how to convert a 15 bit binary string into an sign integer with the MSB as the sign bit?
so for example if I receive:
 
111-1111-1111-1111 => -1
111-1111-1111-1110 => -2
000-0000-0000-0001 => 1
000-0000-0000-0011 => 3
 
Thank you
-bm-
 
 
0 Kudos
Message 1 of 2
(4,085 Views)
Hello,
 
I'm not terribly proud of the implementation (it's not as clean as I'd like it) but I think it's what you want (interprets/converts the pattern you described).  The comments on the block diagram explain the procedure for producing the results.  It should work with or without "-" delimited binary strings, and is not restricted to 15 digit strings.
 
I hope this helps!
 
Best Regards,
 
JLS
 
PS - Please test it thoroughly for your application - I put it together in a matter of minutes.
Best,
JLS
Sixclear
0 Kudos
Message 2 of 2
(4,073 Views)