Solved

Pixel data (ARGB) question

Posted on 2004-08-23
12
562 Views
Last Modified: 2008-02-01
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
Comment
Question by:dr0zaxx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 11878548
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
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11878600
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
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 11878618
> 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:dr0zaxx
ID: 11878681
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
 
LVL 92

Expert Comment

by:objects
ID: 11878695
> 0xFFFFFFFF is way more than that.

because as an int that is a -ve value.
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 11878699
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
 
LVL 92

Expert Comment

by:objects
ID: 11878705
try this:

            int x = 0xffffffff;
            System.out.println(Integer.toHexString(x)+"="+x);
0
 
LVL 92

Expert Comment

by:objects
ID: 11878717
> If you print 0xFFFFFFFF as signed integer you will get 4294967296.

its -1 actually :)
0
 
LVL 1

Author Comment

by:dr0zaxx
ID: 11878738
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
 
LVL 92

Expert Comment

by:objects
ID: 11878758
correct
0
 
LVL 1

Author Comment

by:dr0zaxx
ID: 11878761
Ok thanks a lot.
0
 
LVL 92

Expert Comment

by:objects
ID: 11878784
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
use lov values 2 72
Running JavaFX on JDeveloper 12C 1 78
What's wrong with this code? 4 36
jsp insert to database example 2 64
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question