LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2009, 10:16 PM   #1
shamsheer
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: 0
what is the range of unsigned int


please tell me range of unsigned int and how the negative value are represented in unsigned int

Last edited by shamsheer; 04-06-2009 at 10:18 PM.
 
Old 04-06-2009, 10:18 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Negative values aren't represented by unsigned ints. If an integer is N bits long, it can represent 0 to 2^N-1.
 
Old 04-06-2009, 10:25 PM   #3
shamsheer
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
unsugned int range

I'm reading image...where pixel values are read as unsigned char and assigned to an unsigned int variable... when tranformed this to YUV i'm getting pixel value something like this "2046820352 -268435456" how is that negtive number represented
 
Old 04-06-2009, 10:57 PM   #4
shamsheer
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 0
unsugned int range

I'm reading image...where pixel values are read as unsigned char and assigned to an unsigned int variable... when tranformed this to YUV i'm getting pixel value something like this "2046820352 -268435456" how is that negtive number represented
 
Old 04-07-2009, 02:47 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
You may need to use a union structure so you can decompose the value to it's components.
There are many YUV formats. You might get more info at the www.fourcc.org website.
 
Old 04-07-2009, 08:13 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,457
Blog Entries: 4

Rep: Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920Reputation: 2920
First of all, by all means look for existing libraries that will do what you want to do with your images. Really, there's no reason for you to do what has already been done...

Assuming (for the sake of simplicity) that you know you are dealing with a 32-bit environment, then a standard int type will undoubtedly be 32 bits long. (There are predefined constants that will provide this information in a reliable and platform-independent way, but let's assume for the sake of argument that it's known to be "32.")

The most-significant bit (MSB) will be the sign-bit: 0=positive, 1=negative. This so-called two's complement notation is universally used because it eliminates the need for special rules (and therefore, special hardware designs) to handle signs. If you subtract 2 from the value $00000001 (using hexadecimal notation here...) it naturally becomes $FFFFFFFF, which is "-1." No funky hardware-designs required.

(Note: Hexadecimal notation uses the 16 digits (0-9, A-F), so that each digit represents 4 bits. Therefore, "F" represents 1111. A preceding "$," by convention, indicates to you that the number has been written in hexadecimal.)

If you declare the number to be "unsigned," then the MSB will not be interpreted as a sign-indicator. But, notice that I use the phrase, "be interpreted as." The manner in which the MSB is regarded is entirely up to you, and you must be consistent.

This is particularly true with functions like printf(), where format-string specifiers must be used to indicate that an "unsigned" output-format is to be used. There is nothing "intrinsically special" about the most-significant bit of a particular n-bit quantity: it's up to you.

Last edited by sundialsvcs; 04-07-2009 at 08:14 AM.
 
Old 04-07-2009, 03:00 PM   #7
synss
Member
 
Registered: Jul 2007
Location: Germany
Distribution: Debian, Gentoo, Mac OS X
Posts: 137

Rep: Reputation: 22
Quote:
Originally Posted by shamsheer View Post
pixel value something like this "2046820352 -268435456" how is that negtive number represented
This is undefined behavior. It may, for example, start again from the highest value after decreasing from 0. You do not want that. It is a bug, simply.

Last edited by synss; 04-08-2009 at 12:47 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unsigned long int uint32_t to unsigned char and back MicahCarrick Programming 2 08-02-2009 01:39 AM
invalid conversion from 'int' to 'unsigned int*' tigerhp Programming 2 03-02-2008 04:21 PM
How to print unsigned long int alaios Programming 6 07-14-2005 10:27 AM
print unsigned int alaios Programming 4 06-03-2005 09:34 AM
convert unsigned char * to unsigned long int linux_lover2005 Programming 3 04-26-2005 11:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration