# Println(color) gives strange color number

**URL:** <https://discourse.processing.org/t/println-color-gives-strange-color-number/15654>\
**Category:** Beginners\
**Created:** [November 20, 2019, 6:16am UTC](https://discourse.processing.org/t/println-color-gives-strange-color-number/15654 "2019-11-20T06:16:20Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [November 25, 2019, 5:03pm UTC](https://discourse.processing.org/t/println-color-gives-strange-color-number/15654/18 "2019-11-25T17:03:19Z")

</div>

> [@Ruchi](#):
>
> is all this hassle of negative bit to store the colors efficiently without taking additional storage

An important thing to understand is that, from Processing’s perspective, there is no “negative bit” in a color. The bits are `AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB`.

Because the actual storage for a color is an int, if you `println()` the int, it is interpreted as having a sign bit – but that is just an interpretation of a list of 0s and 1s, and not a helpful one. As long as you don’t try to `println(c)`, there isn’t a hastle – looking at the default print of a color is confusing, because Java’s default interpretation of that primitive value isn’t the way that the bits are meant to be interpreted. However, wrapping each color value (e.g. a pixel) in an object with an attached print method doesn’t make sense for high speed graphics processing – they are stored in ints (rather than Color or Pixel objects) for performance, and you use `alpha()` `red()` `green()` `blue()` helper methods – rather than Pixel.print() or print(Pixel). But the fastest way to do it is with bit-shifting, and this is generally what Processing is doing when working with color channels – it is grabbing the relevant bits directly. There is an example on the reference page for `>>` (right shift):

> **[\>\> (right shift) / Reference](https://processing.org/reference/rightshift.html)**
>
> Shifts bits to the right. The number to the left of the operator is shifted the number of places specified by the number to the right. Each shift to the right halves the number, therefore each right s…

Here is a slightly expanded version of that example:

```auto
color c = color(127, 63, 31);
int a = c >> 24 & 0xff;
int r = c >> 16 & 0xff;
int g = c >> 8 & 0xff;
int b = c >> 0 & 0xff;

println(a, r, g, b);
// 255, 63, 127, 255

println(binary(a));
println(binary(r));
println(binary(g));
println(binary(b));
// 00000000000000000000000011111111
// 00000000000000000000000001111111
// 00000000000000000000000000111111
// 00000000000000000000000000011111

```

---

_[View the full topic](https://discourse.processing.org/t/println-color-gives-strange-color-number/15654)._
