-2

what is 0xf1 mean in the code, I am learning shift operators from GeekForGeek

// Masking sign extension

class GFG {

    public static void main (String[] args) {

       char hex[]={

       '0','1','2','3','4','5',

         '6','7','8','9','a','b','c',

         'd','e','f'

       };

      byte b=(byte) 0xf1; //what does 0xf1 does mean here?

      System.out.println("b = 0x" + hex [(b>>4) & 0x0f] + hex[b & 0x0f]);

    }

}

  • 1
    Does this answer your question? [What does value & 0xff do in Java?](https://stackoverflow.com/questions/11380062/what-does-value-0xff-do-in-java) – phuclv Aug 08 '22 at 07:32
  • Did you try reading the rest of the web page where the code example is? – Karl Knechtel Aug 16 '22 at 10:47

1 Answers1

1

0x is an identifier for hex. 0xf1 is equivalent to 241 in decimal.

Joshua Lewis
  • 166
  • 4
  • thank you, but I forgot to mentioned that I am new to programming, does not know about hex and does decimal means double data type? – Deep Voyager Aug 08 '22 at 06:53
  • 1
    Its about the number type system. You know, we humans use the decimal system. We write numbers as `1, 2, 3, ... 10, 11, ..., 100, 101, ...` Each digit is equivalent to a factor of ten. The rightmost digit is worth 10^0, then 10^1, then 10^2 and so on. Now, you can apply the same system to bases other than 10 as well. For example the binary system `0, 1, 10, 11, 100, 101, 110, ...` where each digit is worth a multiply of `2`. The hexadecimal system (hex) is the system with a base of `16`. Numbers are written as `0, 1, ..., 9, A, B, C, D, E, F, 10, 11, ..., 1A, 1B, ..., 1F, 20, ...`. – Zabuzard Aug 08 '22 at 06:58
  • A line like `int x = 241;` is 100% identical to writing `int x = 0xF1;` or `int x = 0b11110001;` and so on. Its just another way of writing it. – Zabuzard Aug 08 '22 at 06:59
  • 4
    @DeepVoyager you can find answers to most simple questions, like "what is [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal)", by using your favorite Internet search engine. – Jesper Aug 08 '22 at 07:15