Why use hexadecimal constants?

后端 未结 11 995
挽巷
挽巷 2020-12-07 13:16

Sometimes I see Integer constants defined in hexadecimal, instead of decimal numbers. This is a small part I took from a GL10 class:

public static final int          


        
11条回答
  •  难免孤独
    2020-12-07 13:44

    When it comes to big numbers, representing them in hexadecimal makes them more readable, because they're more compact.

    Also, sometimes it is significant for conversions to binary: a hexadecimal number can be very easy converted to binary. Some programmers like to do this, it helps when doing bit operations on the numbers.

    As for the performance gain: no, there is none.

提交回复
热议问题