From: Jordan on 25 May 2010 11:39 I know there must be an easy way to do this, but I'm new to matlab and have not been able to figure it out and have tried searching for a solution without luck. I need to convert a signed integer to a 16-bit sign-extended (2's complement) hex number for output to a file. For example: 3 -> 0003 -3 -> FFFD I've tried using dec2hex(), but it does not support negative number. I've also tried playing around with a fi object but could not quite figure out how to make that work as I needed it to. Any suggestions? Thanks!
From: Walter Roberson on 25 May 2010 11:46 Jordan wrote: > I know there must be an easy way to do this, but I'm new to matlab and > have not been able to figure it out and have tried searching for a > solution without luck. > > I need to convert a signed integer to a 16-bit sign-extended (2's > complement) hex number for output to a file. > > For example: > > 3 -> 0003 > -3 -> FFFD > I've tried using dec2hex(), but it does not support negative number. > I've also tried playing around with a fi object but could not quite > figure out how to make that work as I needed it to. >> sprintf('%x', typecast(int16(-3),'uint16')) ans = fffd
From: Jordan on 25 May 2010 11:47 Oops, sorry ignore this post, accidental double post. "Jordan " <jmcoreymv(a)hotmail.com> wrote in message <htgqvc$1e0$1(a)fred.mathworks.com>... > I know there must be an easy way to do this, but I'm new to matlab and have not been able to figure it out and have tried searching for a solution without luck. > > I need to convert a signed integer to a 16-bit sign-extended (2's complement) hex number for output to a file. > > For example: > > 3 -> 0003 > -3 -> FFFD > > I've tried using dec2hex(), but it does not support negative number. I've also tried playing around with a fi object but could not quite figure out how to make that work as I needed it to. > > Any suggestions? > > Thanks!
From: Jordan on 25 May 2010 11:57 Thanks! That worked great. Walter Roberson <roberson(a)hushmail.com> wrote in message <BhSKn.17682$TL5.2606(a)newsfe24.iad>... > Jordan wrote: > > I know there must be an easy way to do this, but I'm new to matlab and > > have not been able to figure it out and have tried searching for a > > solution without luck. > > > > I need to convert a signed integer to a 16-bit sign-extended (2's > > complement) hex number for output to a file. > > > > For example: > > > > 3 -> 0003 > > -3 -> FFFD > > > I've tried using dec2hex(), but it does not support negative number. > > I've also tried playing around with a fi object but could not quite > > figure out how to make that work as I needed it to. > > >> sprintf('%x', typecast(int16(-3),'uint16')) > ans = > fffd
From: Ken Garrard on 25 May 2010 12:15 "Jordan " <jmcoreymv(a)hotmail.com> wrote in message <htgqte$qnn$1(a)fred.mathworks.com>... > I know there must be an easy way to do this, but I'm new to matlab and have not been able to figure it out and have tried searching for a solution without luck. > > I need to convert a signed integer to a 16-bit sign-extended (2's complement) hex number for output to a file. > > For example: > > 3 -> 0003 > -3 -> FFFD > > I've tried using dec2hex(), but it does not support negative number. I've also tried playing around with a fi object but could not quite figure out how to make that work as I needed it to. > > Any suggestions? > > Thanks! dec2hex((f<0)*65536+f) Ken
|
Next
|
Last
Pages: 1 2 Prev: Convert signed integer to a 16-bit hex number Next: minimum stationary points |