Thread View: borland.public.jbuilder.java.language
3 messages
3 total messages
Started by Rick
Wed, 15 Jun 2005 13:00
Converting int to unsigned int
Author: Rick
Date: Wed, 15 Jun 2005 13:00
Date: Wed, 15 Jun 2005 13:00
14 lines
1304 bytes
1304 bytes
Hi,
Probably a simple question: how to convert a signed int to an unsigned int?
My applets gets a string value holding a 16-bits integer value. Before I
want to display it, this value needs to be converted to an unsigned int(16
bits) and then back in a string. So the input string "32767" becomes
"65535".
I thought the conversion would be this,
uint16 = int16 * 2 +1
but I'm not sure though
Greetings,
Rick
Re: Converting int to unsigned int
Author: Alexey N. Solofnenko
Date: Wed, 15 Jun 2005 14:06
Date: Wed, 15 Jun 2005 14:06
26 lines
1674 bytes
1674 bytes
I would suggest: (value>=0 ? value : 65536+value). 32767 should not be changed - it is already a positive integer, but -1 is actually 65535. - Alexey. Rick wrote: > Hi, > > Probably a simple question: how to convert a signed int to an unsigned int? > > My applets gets a string value holding a 16-bits integer value. Before I > want to display it, this value needs to be converted to an unsigned int(16 > bits) and then back in a string. So the input string "32767" becomes > "65535". > I thought the conversion would be this, > uint16 = int16 * 2 +1 > but I'm not sure though > > Greetings, > Rick > > -- Alexey N. Solofnenko home: http://trelony.cjb.net/
Re: Converting int to unsigned int
Author: Shankar Unni
Date: Wed, 15 Jun 2005 21:37
Date: Wed, 15 Jun 2005 21:37
13 lines
1227 bytes
1227 bytes
Rick wrote: > I thought the conversion would be this, > uint16 = int16 * 2 +1 > but I'm not sure though FAQ. uint16 = int16 & 0xffff; Ditto for "signed bytes to unsigned bytes": ubyte = sbyte & 0xff;
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads