Hex VS Integer

  • Thread starter Thread starter Charlie Brown
  • Start date Start date
C

Charlie Brown

Out of curiosity, what is the advantage of the following...

opacity = CInt(IIf(pressed, &HCC, &H7F))

Over...

opacity = CInt(IIf(pressed, 204, 127))
 
Charlie said:
Out of curiosity, what is the advantage of the following...

opacity = CInt(IIf(pressed, &HCC, &H7F))

Over...

opacity = CInt(IIf(pressed, 204, 127))

Readability, depending on the context - consider the relationship of the
digits to a number written in binary.

I just wish the editor would leave in leading zeros if I type them in.

Andrew
 
Readability, depending on the context - consider the relationship of the
digits to a number written in binary.

I just wish the editor would leave in leading zeros if I type them in.

Andrew

I guess I have always subscribed to naming constants vs magic numbers
in the code.

minOpacity = 127
maxOpacity = 204
opacity = CInt(IIf(pressed, maxOpacity, minOpacity))
 
Charlie Brown said:
I guess I have always subscribed to naming constants vs magic numbers
in the code.

minOpacity = 127
maxOpacity = 204
opacity = CInt(IIf(pressed, maxOpacity, minOpacity))

Well, that's even better. But still, depending on the context, it's better
to use the hexadecimal notation (in the assignment of the values to the
named constants) in order to make the bits set in the value more visible.
 
Well, that's even better. But still, depending on the context, it's better
to use the hexadecimal notation (in the assignment of the values to the
named constants) in order to make the bits set in the value more visible.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -

- Show quoted text -

Interesting, does anyone have an example of a good situation where
seeing the hexadecimal notation is beneficial vs integer notation?
 
Interesting, does anyone have an example of a good situation where
seeing the hexadecimal notation is beneficial vs integer notation?

Without giving specifics due to not being able to remember them...
....Hex is good for colors as each pair of digits represents a different component
of the color.

&H11223344 might represent
11 = alpha
22 = red
33 = Blue
44 = Green
and it'e relatively clear how much of each is represented by this.
 
Charlie Brown said:
Interesting, does anyone have an example of a good situation where
seeing the hexadecimal notation is beneficial vs integer notation?

Anytime you need to use a bitmap to set a value it's easier to use the hex
than decimal.

Mike Ober.
 
Back
Top