Obtaining the Most Significant or Least Significant Bits of a Number : Binary Bit « Language Basics « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » Language Basics » Binary BitScreenshots 
Obtaining the Most Significant or Least Significant Bits of a Number
Obtaining the Most Significant or Least Significant Bits of a Number


using System;
using System.Data;


class Class1{
        static void Main(string[] args){
            int number = 25;
            short num = 25;
            Console.WriteLine(GetMSB(number));
            Console.WriteLine(GetConvertMSB(number));
            Console.WriteLine(GetLSB(number));
            Console.WriteLine(GetConvertLSB(number));
            Console.WriteLine(GetMSB(num));
            Console.WriteLine(GetLSB(num));

        }
        public static int GetMSB(int value)
        {
            return (int)(value & 0xFFFF0000);
        }
        public static int GetConvertMSB(int value)
        {
            return (value & Convert.ToInt32("11111111111111110000000000000000"2));
        }

        public static int GetLSB(int intValue)
        {
            return (intValue & 0x0000FFFF);
        }

        public static int GetConvertLSB(int intValue)
        {
            return (intValue & Convert.ToInt32("11111111111111110000000000000000"2));
        }
        
        public static int GetMSB(short intValue)
        {
            return (intValue & 0xFF00);
        }

        public static int GetLSB(short intValue)
        {
            return (intValue & 0x00FF);
        }

}

           
       
Related examples in the same category
1. Using the Bitwise Complement Operators with Various Data TypesUsing the Bitwise Complement Operators with Various Data Types
2. Binary Data TestBinary Data Test
3. Binary Network Byte OrderBinary Network Byte Order
w__w__w__._j___a___v___a__2__s___.__com___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.