tags:

views:

33

answers:

3

I'm looking at some code written by a former employee where I work and I'm noticing that he sometimes uses hexadecimal notation, and other times decimal. Since he's long gone I can't ask him why, so I hope someone here could take a look and enlighten me.

   command.Parameters.Add("PI_EMPLOYEE_NUM", 
          OracleDbType.Varchar2, Trim(cn, 50), 
          ParameterDirection.Input);
   command.Parameters.Add("PI_EMPLOYEE_DISPLAY_NM", 
          OracleDbType.Varchar2, Trim(displayName, 0xff), 
          ParameterDirection.Input);
   command.Parameters.Add("PI_EMPLOYEE_ADDR_TXT", 
          OracleDbType.Varchar2, Trim(streetAddress, 0xff), 
          ParameterDirection.Input);
   command.Parameters.Add("PI_EMPLOYEE_MAIL_CD", 
          OracleDbType.Varchar2, Trim(postOfficeBox, 50), 
          ParameterDirection.Input);
A: 

It looks like he's using hex for strings and decimal for numbers.

Myles
+1  A: 

Generally, it makes sense to use hex when the number being represented is more of a technical computer or hardware limitation parameter, as these types of values are often based on base-2 constructs because the internal limitation is tied to the number of potential values that can be represented by some binary number (a value that muist be stored in an 8 bit byte, or in a 16 bit unsigned integer, for example)

Decimal representations are more commonly used when the value is a business limitation, driven by some exrternal business model rule that has nothing to do with computers or technical details.

This may not be what your long-gone co-worker did, but it is a commonly used pattern. Other than this, there is no functional difference in the two representations.

Charles Bretana
A: 

I suppose he uses hexadecimal for 0xff (255) to signify that it is (2^8 - 1) for a reason. I'm not sure what the reason is though. Maybe Oracle works better with column widths of powers of two? I've never heard about that before so I don't know if it is true.

DrJokepu