Reputation:
I have a byte array in which I store both hexadecimal and decimal values. I want to search for hexadecimal 1 so I write a hexadecimal value to the varibla SOH
But when I compare it to a decimal value
int SOH = 0X01;
if (SOH == 1)
it is showing true. Is this correct?
Upvotes: 2
Views: 5855
Reputation: 272257
Your byte arrays will just store byte values. The hexadecimal (or decimal, or octal) is just the representation of that value in the source code. Once stored, they're all the same value e.g.
0x01 == 1 == 01
(the last being octal)
So checking for a particular value is the same code. A value won't know if it's been represented as hex/dec/oct.
Upvotes: 5
Reputation: 984
How is the data in the byte array stored as hexadecimal and decimal? A byte array contains bytes.
byte[] decimal = new byte[] {1,10 }; byte[] hexa = new byte[] {0x1,0xa };
These contain the same values, you can compare them directly, you don't need any specific code.
Upvotes: 1