• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • Last Modified:

Pixel data (ARGB) question

Hi guys,

I am currently studying on how Java stores the ARGB of a pixel data into an integer. However, I have a little problem understanding one area. This is it:

According to a certain article, an integer in Java is 32 bits (4 bytes). The first 8 bits store the alpha, the next 8 bits store the red component, the next 8 bits store the green component, and the final 8 bits store the blue component. Now, imagine I have an opaque white color. Does this mean that the integer that store this pixel data can be represented this way in hex: 0xFFFFFFFF? If yes, here comes my problem. How can 0xFFFFFFFF fit into one integer? This value exceeds the limit of an integer value. If I remember correctly, the first bit is always the sign type of the number (0 means positive, 1 means negative). Yet the article claims that "FF" is used for opaque (no transparency) colors.

What is happening?
0
dr0zaxx
Asked:
dr0zaxx
  • 6
  • 3
  • 2
  • +1
1 Solution
 
Farzad AkbarnejadCommented:
Hi,
We have Signed and Unsigned Integer. In Unsigned Integer we haven't sign bit. Unsigned 32 bit Integers start from 0 to 4294967295.

-FA
0
 
sudhakar_koundinyaCommented:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#toHexString(int)

This method says you can represent the value as unsigned Hex values
0
 
objectsCommented:
> This value exceeds the limit of an integer value

No it doesn't, it uses 4 bytes which is the size of int as you stated.
How that value is interpreted as an integer is irrelevent as it uses the byte values directly.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
dr0zaxxAuthor Commented:
To objects:

But how come it doesn't exceed?

While it is definitely true that I am still using 4 bytes, but integers in Java are signed.

I think the limit for integer in Java is 2147483647, which is equivalent to 0x7FFFFFFF. 0xFFFFFFFF is way more than that.

Sorry but maybe you can elaborate on what you meant? I do not understand.
0
 
objectsCommented:
> 0xFFFFFFFF is way more than that.

because as an int that is a -ve value.
0
 
Farzad AkbarnejadCommented:
You save 4 bytes in 32 bits. The presentation of number determine its sign. If you print 0xFFFFFFFF as signed integer you will get 4294967296.
Colors don't need to be aware of sign of numbers. They need 4 bytes for storage.

-FA
0
 
objectsCommented:
try this:

            int x = 0xffffffff;
            System.out.println(Integer.toHexString(x)+"="+x);
0
 
objectsCommented:
> If you print 0xFFFFFFFF as signed integer you will get 4294967296.

its -1 actually :)
0
 
dr0zaxxAuthor Commented:
So do you mean that it doesn't matter what the resultant integer is? I only care about what bits the integer consist of?
0
 
objectsCommented:
correct
0
 
dr0zaxxAuthor Commented:
Ok thanks a lot.
0
 
objectsCommented:
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now