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 7702181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:10:10+00:00 2026-05-31T23:10:10+00:00

I have a method in c# with only 1 parameter (it is an override

  • 0

I have a method in c# with only 1 parameter (it is an override so I cannot change its signature to incorporate more parameters):

read_address(long adr)

where adr is the address memory I want to read, but I have to pass the address and indicating at the same time if the address to read is 16 or 32 bit and if 32 bits, furthermore I have to indicate if I want to read upper or lower word so I would like to know an efficient way to do this using parameter adr.

I have thought to build a mask, for example, If I want to read address 614 (decimal), I can add two digits before or back:

10614 : first digit 1 indicates size=32bit and second one 0=lower word
11614 : first digit 1 indicates size=32bit and second one 1=upper word

for indicate 16 bit, no necessary to indicate lower or upper so:

00614 = 614 will indicate 16-bit.

Also I can done this by putting those two digits back:

61410
61411

So when I receive this number through addr parameter I have to parse it to know if this is a 16 or 32 bit and in case of 32 if it is lower or upper word.

EDITED:

I think I haven’t explained well…

For example, figure that this method, read_address, receive and address (addr) to read. THis is called from another method, method_A, which knows if this is 16 or 32 bit and if 32 bit it splits into two word. Better an example, for read 614:

Method_A(....)
{
   if 16-bit then

   {
       call read_address(620) // Supose 620 is 16 bit
   }

   if 32-bit then

   { 

       // suppose 614 is 32 bit so split into two reads

       call read_address(61410)  // to read first word

       call read_address(61411) // to read second word

   } 

}

so in read_address I have to know if it is 16 or 32 bit and if 32-bit, I also have to know if it is lower or upper word.

read_address(long addr)

{

    // decode if addr is 16 or 32 bit and if 32 bit, decode if lower

    // or upper word and do some stuff


    // So suppose it arrives 61410... how to decode it in order to know,

    // address to read is 614 and is 32-bit (1) and I want to read lower word (0)


}
  • 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. Editorial Team
    Editorial Team
    2026-05-31T23:10:12+00:00Added an answer on May 31, 2026 at 11:10 pm

    You mention the “upper/higher” word only counts when addr specifies a 32-bit address – I hope you meant it only counts on 16-bits? (if not, how would you know whether the value “10” is a mask or an adress?)

    I wouldn’t use decimal positions for the mask, but rather split the 64 bits into two 32 bit numbers (integers), and use binary flags.

    The example 614 as a 64-bit number in binary would then be (I hope I got the endianness right, but it should illustrate the situation):

    00000010 00000000 00000000 00000000 01100110 00000010 00000000 00000000
    |              Mask               | |            Address              |
    

    You can then use a [Flags] enum to define the mask, and cast the mask-integer to that enum. Here’s an example of creating and parsing the address:

        public void Main()
        {
            // Some test values.
            ushort address16 = ushort.MaxValue;
            uint address32 = uint.MaxValue;
    
            // Upper:
            ulong valueUpper = address16;           // Value contains 0x000000000000FFFF
            valueUpper = valueUpper << 48;          // Value contains 0xFFFF000000000000
            valueUpper += (uint)Mask.Upper;         // Value contains 0xFFFF000000000001
    
            // Lower:
            ulong valueLower = address16;           // Value contains 0x000000000000FFFF
            valueLower = valueLower << 32;          // Value contains 0x0000FFFF00000000
            // No need to set a 0-bit, it is already 0
    
            // DWord:
            ulong valueDword = address32;           // Value contains 0x00000000FFFFFFFF
            valueDword = valueDword << 32;          // Value contains 0xFFFFFFFF00000000
            valueDword += (uint)Mask.DoubleWord;    // Value contains 0xFFFFFFFF00000010
    
            ulong addr1 = ParseAddress((long)valueUpper);
            ulong addr2 = ParseAddress((long)valueLower);
            ulong addr3 = ParseAddress((long)valueDword);
        }
    
        public ulong ParseAddress(long address)
        {
            // Casting to ulong, as negative values don't make sense in addresses or bitwise operations.
            ulong value = (ulong)address;
    
            // Take the mask from the least significant bits
            Mask mask = (Mask)(value & uint.MaxValue);
    
            // Shift the mask bytes "off" the addr, get the remaining address. 
            ulong addr = ((ulong)value >> 32);
    
            // Is the doubleword bit set?
            if ((mask & Mask.DoubleWord) == Mask.DoubleWord)
            {
                return addr;
            }
            else if ((mask & Mask.Upper) == Mask.Upper)
            {
                return (addr >> 16);
            }
            else
            {
                return addr;
            }
        }
    
        [Flags]
        public enum Mask : uint
        {
            Upper = 1,
            DoubleWord = 2,
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have only simple data types in method signature of service (such as int,
I have method in a class that I need to make sure is only
What would I do if I want to have a generic method that only
The only reliable method that I a have found for using a script to
When we have a static method in a class it access only static members
serial.write() method in pyserial seems to only send string data. I have arrays like
I have these two methods on a class that differ only in one method
In my Site.Master file, I have 3 simple ViewData parameters (the only 3 in
What do you do with classes that have no member data, only methods? Do
I have found only two methods (SaveFile, LoadFile) which save in a file. How

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.