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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 behavior of datatype UINT
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

TreeNode

64 Posts

Posted - 03/22/2010 :  06:41:27 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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!!

greg

USA
1378 Posts

Posted - 03/23/2010 :  3:38:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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);
Go to Top of Page

TreeNode

64 Posts

Posted - 03/23/2010 :  8:26:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry, my fault...

thank you very much for your advice!

|-- TreeNode
...|-- a??
...|-- ha!!
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000