The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 behavior of datatype UINT

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
TreeNode Posted - 03/22/2010 : 06:41:27 AM
Origin Ver.8 SR6:
Operating System: XP

Hi,

using datatype UINT behaves not in the way I would expect.

void integer_data_types_ex1()
{
	int iNum;
	
	UINT uiNum;
	USHORT usNum;
	
	iNum = -5;
	uiNum = (UINT)iNum;		// value stays the same
	usNum = (USHORT)iNum;	
	
	printf("unsigned integer: %d\n", uiNum);	// -5
	printf("unsigned short: %d\n", usNum);		// 65531
}


|-- TreeNode
...|-- a??
...|-- ha!!
2   L A T E S T    R E P L I E S    (Newest First)
TreeNode Posted - 03/23/2010 : 8:26:20 PM
Sorry, my fault...

thank you very much for your advice!

|-- TreeNode
...|-- a??
...|-- ha!!
greg Posted - 03/23/2010 : 3:38:09 PM
Do not confuse printf options with how a value is internally handled.
The %d option means to treat the value as a signed decimal.

Try these lines:

// this outputs 4294967291 which is 2^32 - 5
printf("unsigned integer: %u\n", uiNum);
// this outputs 65531 which is 2^16 - 5
printf("unsigned short: %u\n", usNum);

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000