Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 186389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:38:18+00:00 2026-05-11T15:38:18+00:00

Strange how I can do it in C++,but not in C#. To make it

  • 0

Strange how I can do it in C++,but not in C#.

To make it clear,i’ll paste the two functions in C++ and then in C# and mark the problematic lines in the C# code with a comment ‘//error’. What the two function does is encoding the parameter and then add it in to a global variable named byte1seeds.

These are the functions in C++

//Global var:  unsigned char byte1seeds[3];  unsigned long GenerateValue( unsigned long * Ptr ) { unsigned long val = *Ptr; for( int i = 0; i < 32; i++ )     val = (((((((((((val >> 2)^val) >> 2)^val) >> 1)^val) >> 1)^val) >> 1)^val)&1)|((((val&1) << 31)|(val >> 1))&0xFFFFFFFE); return ( *Ptr = val ); }  void SetupCountByte( unsigned long seed ) { if( seed == 0 ) seed = 0x9ABFB3B6; unsigned long mut = seed; unsigned long mut1 = GenerateValue( &mut ); unsigned long mut2 = GenerateValue( &mut ); unsigned long mut3 = GenerateValue( &mut ); GenerateValue( &mut ); unsigned char byte1 = (mut&0xFF)^(mut3&0xFF); unsigned char byte2 = (mut1&0xFF)^(mut2&0xFF); if( !byte1 ) byte1 = 1; if( !byte2 ) byte2 = 1; byte1seeds[0] = byte1^byte2; byte1seeds[1] = byte2; byte1seeds[2] = byte1; } 

Now the C# code:

I’ve changed the function GenerateValue.Instead of having a pointer as a parameter, it has a ulong parameter.

To call it and change both values i use:

  1. ulong mut1 = GenerateValue(mut);
  2. mut = mut1;

Here are the translated functions(the problematic lines are marked with ‘//error’);

//Global var: public static byte[] byte1seeds = new byte[3];  public static ulong GenerateValue(ulong val) {     for( int i = 0; i < 32; i++ )         val = (((((((((((val >> 2)^val) >> 2)^val) >> 1)^val) >> 1)^val) >> 1)^val)&1)|((((val&1) << 31)|(val >> 1))&0xFFFFFFFE);     return val ; }  public static void SetupCountByte( uint seed ) {     if( seed == 0 ) seed = 0x9ABFB3B6;     ulong mut = seed;     ulong mut1 = GenerateValue(mut);     mut = mut1;     ulong mut2 = GenerateValue(mut);     mut = mut2;     ulong mut3 = GenerateValue(mut);     mut = mut3;     mut = GenerateValue(mut);     byte byte1 = (mut & 0xFF) ^ (mut3 & 0xFF); //error     byte byte2 = (mut1 & 0xFF) ^ (mut2 & 0xFF); //error     if( byte1 != 0 )         byte1 = 1;     if( byte2 != 0 )         byte2 = 1;     byte1seeds[0] = byte1^byte2; //error     byte1seeds[1] = byte2;     byte1seeds[2] = byte1; } 

The error is:

Cannot implicitly convert type ‘ulong’ to ‘byte’. An explicit conversion exists (are you missing a cast?)

edit:the error at problematic line 3 is:

Cannot implicitly convert type ‘int’ to ‘byte’. An explicit conversion exists (are you missing a cast?)

Here comes the question: How to solve those errors?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T15:38:19+00:00Added an answer on May 11, 2026 at 3:38 pm

    Add a (byte) to cast it. As you could lose precision, you have to tell the compiler that the value will fit into a byte, i.e.

    byte byte1 = (byte)((mut & 0xFF) ^ (mut3 & 0xFF)); byte byte2 = (byte)((mut1 & 0xFF) ^ (mut2 & 0xFF)); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's very strange because phpmyadmin is not in document root, but still can visit
Slightly strange question, but hopefully someone can help. In essence, if the time was
I have run into a very strange behaviour I can’t make sense of. I
I have a strange error in my code and i can't see the problem.
I'll try and make this clear; I've got two classes; GPU(Object) , for general
I'm trying to make some kind of strange polymorphism on C++: I have two
This may seem strange... but I'm wondering if there is anyway to make a
I have a strange problem in my code that I really can't explain and
I'm getting a strange warning I can't fix with Symfony2 version v2.0.12. This was
I can't understand the strange behaviour of sessions in CakePHP controller: class UsersController extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.