Question

in C++ An unsigned int, x, represents 4 color values: alpha, red, green, blue (in that...

in C++

An unsigned int, x, represents 4 color values: alpha, red, green, blue (in that order). Each value is a number from 0..255. Using bit manipulation only (<<, |, & , etc.), write code to pull the red value from x. Then using arithmetic operators only (+, /, %, etc.), write code to pull the red value from x.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>

using namespace std;

int main() {
    unsigned int color = 0xF000FF0F;

    unsigned int red = (color >> 24) & 0xFF;

    cout << "Value of red is " << red << endl;  // F0 which is 240
    return 0;
}

Value of red is 240

Add a comment
Know the answer?
Add Answer to:
in C++ An unsigned int, x, represents 4 color values: alpha, red, green, blue (in that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In computer systems color is represented by RGB format (Red. Green and Blue color components) where...

    In computer systems color is represented by RGB format (Red. Green and Blue color components) where each component can hold a value from 0 to 255. Implement all functions and operators given in the following header file: # include using namespace std; class public://Default constructor//Constructor with parameters//Copy constructor//Getters//Setters//a function that increment all components//a print function to print all components//a function to add two private: int red; int green; int blue; Test your class with an appropriate main ()

  • 3.22 LAB: Remove gray from RGB Summary: Given integer values for red, green, and blue, subtract...

    3.22 LAB: Remove gray from RGB Summary: Given integer values for red, green, and blue, subtract the gray from each value. Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded...

  • Summary: Given integer values for red, green, and blue, subtract the gray from each value. Python...

    Summary: Given integer values for red, green, and blue, subtract the gray from each value. Python Language Computers represent color by combining the sub-colors red, green, and blue (rgb). Each sub-color's value can range from 0 to 255. Thus (255, 0, 0) is bright red, (130, 0, 130) is a medium purple, (0, 0, 0) is black, (255, 255, 255) is white, and (40, 40, 40) is a dark gray. (130, 50, 130) is a faded purple, due to the...

  •     class Circle    {    public:        enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN,...

        class Circle    {    public:        enum Color {UNDEFINED, BLACK, BLUE, GREEN, CYAN, RED};        Circle(int = 0, int = 0, double = 0.0, Color = UNDEFINED);        void setX(int);        void setY(int);        void setRadius(double);        void setColor(Color);        int getX() const;        int getY() const;        double getRadius() const;        Color getColor() const;           private:        int x;        int y;   ...

  • lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack...

    lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack; int r_unpack, g_unpack,b_unpack; int alpha = AlphaValue; printf("enter R value (0~255): "); scanf("%d",&r); printf("enter G value (0~255): "); scanf("%d",&g); printf("enter B value (0~255): "); scanf("%d",&b); while(! (r<0 || g<0 || b <0) ) { printf("A: %d\t", alpha); printBinary(alpha); printf("\n"); printf("R: %d\t", r); printBinary(r); printf("\n"); printf("G: %d\t", g); printBinary(g); printf("\n"); printf("B: %d\t", b); printBinary(b); printf("\n"); /* do the packing */ //printf("\nPacked: value %d\t", rgb_pack); printBinary(rgb_pack);printf("\n");...

  • Use the welch-powell algorithm to color the following graph. First color the graph using RED, then GREEN, then BLUE, followed by YELLOW, BLACK, and GRAY, if needed. Use the Welch-Powell Algorithm to...

    Use the welch-powell algorithm to color the following graph. First color the graph using RED, then GREEN, then BLUE, followed by YELLOW, BLACK, and GRAY, if needed. Use the Welch-Powell Algorithm to color the following graph. (This is the algorithm we learned in class) You Must use the Welch-Powell algorithm otherwise no credit will be given. First color the graph using RED, then GREEN, then BLUE, followed by YELLOW and BLACK, and GRAY, if needed. If the algorithm gives you...

  • 16. What do the following two code fragments do given integers a and b? a-a +...

    16. What do the following two code fragments do given integers a and b? a-a + b b-a b just print the code you wrote with comments RGBA color format. Some of Java's classes (Bufferedlmage, PixelGrabber) use a special encoding called RGBA to store the color of each pixel. The format consists of tour integers, representing the red, green, and blue intensities from 0 (not present) to 255 (fully used), and also the alpha transparency value from O (transparent) to...

  • In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned...

    In C, thanks. #include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned int * flag-holder, int flag-position); int check-flag (unsigned int flag-holder , int flag-position); void display -32_flags (unsigned int flag-holder); int main(int argc, char* argv (1) unsigned int flag -holder = 0; set-flag (& flag-holder, 3); set-flag (& flag-holder, 16); set-flag (& flag-holder, 31); display-32-flags (flag-holder); unset-flag(& flag-holder , 31); unset-flag (& flag-holder, 3); set-flag (& flag-holder , 9); display-32-flags (flag-holder ); return 0; Write...

  • use MATLAB to upload the following: an image that you want to process (can be taken...

    use MATLAB to upload the following: an image that you want to process (can be taken yourself or downloaded from the internet) a script that processes the image in TWO ways. manipulates the colors averages pixels together Please make sure the script displays the images (like how I did with the 40 and 80 pixel averaging) so I can easily compare them to the original. Make sure to COMMENT your code as well. Homework 13 Please upload the following: an...

  • Gases Color Energy (E, ev) Wavelength (λ, nm) 1/λ (1/nm) H2 Blue Green Orange Red 2.31...

    Gases Color Energy (E, ev) Wavelength (λ, nm) 1/λ (1/nm) H2 Blue Green Orange Red 2.31 2.30 2.10 2.00 538 540 580 620 1.86 x 10^-3 1.85 x 10^-3 1.72 x 10^-3 1.61 x 10^-3 Ne Green Yellow Yellow Orange Orange Red 2.25 2.14 2.10 2.01 2.05 1.90 550 580 590 605 610 650 1.82 x 10^-3 1.72 x 10^-3 1.69 x 10^-3 1.65 x 10^-3 1.64 x 10^-3 1.54 x 10^-3 Hg Purple Blue Green Yellow Red 2.85 2.52...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT