Click here to Skip to main content
15,888,241 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
Int16 [,]sbox={{18,23,C6,E8,87,B8,01,4F,36,A6,D2,F5,79,6F,91,52},
                {60,BC,9B,8E,A3,0C,7B,35,1D,E0,D7,C2,2E,4B,FE,57},
                {15,77,37,E5,9F,F0,4A,CA,58,C9,29,0A,B1,A0,6B,85},
                {BD,5D,10,F4,CB,3E,05,67,E4,27,41,8B,A7,7D,95,C8},
                {FB,EE,7C,66,DD,17,47,9E,CA,2D,BF,07,AD,5A,83,33},
                {63,02,AA,71,C8,19,49,C9,F2,E3,5B,88,9A,26,32,B0},
                {E9,0F,D5,80,BE,CD,34,48,FF,7A,90,5F,20,68,1A,AE},
                {B4,54,93,22,64,F1,73,12,40,08,C3,EC,DB,A1,8D,3D},
                {97,00,CF,2B,76,82,D6,1B,B5,AF,6A,50,45,F3,30,EF},
                {3F,55,A2,EA,65,BA,2F,CO,DE,1C,FD,4D,92,75,06,8A},
                {B2,E6,0E,1F,62,D4,A8,96,F9,C5,25,59,84,72,39,4C},
                {5E,78,38,8C,C1,A5,E2,61,B3,21,9C,1E,43,C7,FC,04},
                {51,99,6D,0D,FA,DF,7E,24,3B,AB,CE,11,8F,4E,B7,EB},
                {3C,81,94,F7,B9,13,2C,D3,E7,6E,C4,03,56,44,7F,A9},
                {2A,BB,C1,53,DC,0B,9D,6C,31,74,F6,46,AC,89,14,E1},
                {16,3A,69,09,70,B6,C0,ED,CC,42,98,A4,28,5C,F8,86}};

I want this array elements to be in hexadecimal. There is error in only underlined sections of this code. My ques.is-
How to store hex no.s in an array? and
why there is errors in only four lines?
Posted
Updated 4-Feb-12 9:42am
v3

Wow. The reason you long how SOME errors, is that any number that has no letter in it, is a valid base 10 number. I believe you can use 0x, as 0xBD, to specify a number in hex. If you didn't specify it, how does the compiler tell between 55 and 0x55 ?
 
Share this answer
 
Comments
Ratika Agarwal 5-Feb-12 13:07pm    
thanks for the idea of 0x.
This notation will work:
Int16[,] sbox1 = new Int16[,]
{
    {0x18,0x23,0xC6,0xE8,0x87,0xB8,0x01,0x4F,0x36,0xA6,0xD2,0xF5,0x79,0x6F,0x91,0x52},
    {0x60,0xBC,0x9B,0x8E,0xA3,0x0C,0x7B,0x35,0x1D,0xE0,0xD7,0xC2,0x2E,0x4B,0xFE,0x57},
    {0x15,0x77,0x37,0xE5,0x9F,0xF0,0x4A,0xCA,0x58,0xC9,0x29,0x0A,0xB1,0xA0,0x6B,0x85}
};
Or this:
Int16[,] sbox2 = new Int16[3, 16]
{
    {0x18,0x23,0xC6,0xE8,0x87,0xB8,0x01,0x4F,0x36,0xA6,0xD2,0xF5,0x79,0x6F,0x91,0x52},
    {0x60,0xBC,0x9B,0x8E,0xA3,0x0C,0x7B,0x35,0x1D,0xE0,0xD7,0xC2,0x2E,0x4B,0xFE,0x57},
    {0x15,0x77,0x37,0xE5,0x9F,0xF0,0x4A,0xCA,0x58,0xC9,0x29,0x0A,0xB1,0xA0,0x6B,0x85}
};
Or this:
C#
Int16[,] sbox3 =
{
    {0x18,0x23,0xC6,0xE8,0x87,0xB8,0x01,0x4F,0x36,0xA6,0xD2,0xF5,0x79,0x6F,0x91,0x52},
    {0x60,0xBC,0x9B,0x8E,0xA3,0x0C,0x7B,0x35,0x1D,0xE0,0xD7,0xC2,0x2E,0x4B,0xFE,0x57},
    {0x15,0x77,0x37,0xE5,0x9F,0xF0,0x4A,0xCA,0x58,0xC9,0x29,0x0A,0xB1,0xA0,0x6B,0x85}
};
So it looks like you must need to add "Ox" in front of every hex value.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900