0

I have a line of code in a piece of C# I'm analyzing.

`random.next(0xf4240, 0x98967f).ToString();'

I know the command line is generating a number between the specified ranges and returning it as a string. Whats a little odd to me is the '0xf' and the '0x#####f'

I looked up that the 0xf is supposed to return a nybbie but I'd realy like to get an idea of what the raw values would be. Any help would be great.

Thanks.

John
  • 21
  • 2

3 Answers3

2

The prefix 0x is how you specify hexadecimal values in C# and a number of other languages. It's my belief that hexadecimal can only specify integer values, although I may be wrong.

In your case, 0xf4240 is the same as F4240 in hexadecimal, or a 1.000.000 in decimal. 0x98967f is the same as 9.999.999 in decimal.

One thing, this code was obviously obfuscated on purpose, which is baaaad. There seems to be no need to provide those values in hexadecimal.

Bruno Brant
  • 8,226
  • 7
  • 45
  • 90
1

The command line isn't generating anything - your C# application (which happens to output to the command line) is calculating a pseudo-random number between 1000000 and 9999999 (you are passing in the hex representations).

Adam
  • 15,537
  • 2
  • 42
  • 63
0

In C#, 0x is used as prefix to represent hexadecimal integer literals. See the spec

In your case, f4240 and 98967f are just two integers represented in hexadecimal system.

Update: As @codesparkle has stated they represent 1000000 and 9999999 respectively

prashanth
  • 2,059
  • 12
  • 13
  • Thanks for that, Actually the 0X I know from c & c++ and I think even Java but I hit a posting on the web somewhere that indicated C# uses 0xf as a "nybbie"?? Looks like a variation on nibble?!? The different method of expressing the values also had me second guessing myself. They do output to a variable so I'm sorry if I confused anyone by leaving that out. – John Sep 19 '12 at 17:47