Chandu yadav

Chandu yadav

810 Articles Published

Articles by Chandu yadav

Page 3 of 81

Python program to extract 'k' bits from a given position?

Chandu yadav
Chandu yadav
Updated on 24-Mar-2026 2K+ Views

Bit extraction involves extracting a specific number of bits from a given position in a number's binary representation. This is useful in low-level programming, cryptography, and data manipulation tasks. Understanding the Problem Given a number, we need to extract 'k' consecutive bits starting from a specific position 'pos' (counted from the right, starting at 0). The extracted bits are then converted back to decimal. Example Input: number=170, k=5, pos=2 Output: 21 Binary of 170: 10101010 Position 2 from right, extract 5 bits: 01010 Decimal value: 21 Algorithm The ...

Read More

How to Find ASCII Value of Character using Python?

Chandu yadav
Chandu yadav
Updated on 24-Mar-2026 273 Views

The ord() function in Python returns the ASCII (ordinal) value of a character. This is useful for character encoding, sorting operations, and working with character data. Syntax ord(character) Parameters: character − A single Unicode character Return Value: Returns an integer representing the ASCII/Unicode code point of the character. Finding ASCII Value of a Single Character char = 'A' ascii_value = ord(char) print(f"ASCII value of '{char}' is {ascii_value}") ASCII value of 'A' is 65 Finding ASCII Values of Multiple Characters You can iterate through ...

Read More

Why python for loops don't default to one iteration for single objects?

Chandu yadav
Chandu yadav
Updated on 24-Mar-2026 212 Views

Python's for loop is designed to work only with iterable objects. When you try to use a for loop with a single non-iterable object, Python raises a TypeError instead of defaulting to one iteration. Understanding Iterables vs Non-Iterables An iterable is any Python object that implements the iterator protocol by defining the __iter__() method. Common iterables include lists, strings, tuples, and dictionaries. # These are iterable objects numbers = [1, 2, 3] text = "hello" coordinates = (10, 20) for item in numbers: print(item) 1 2 3 ...

Read More

How to check for redundant combinations in a Python dictionary?

Chandu yadav
Chandu yadav
Updated on 24-Mar-2026 206 Views

Python dictionaries are hashmaps where each key can only have one associated value. This prevents redundant key combinations by design. When you assign a new value to an existing key, it overwrites the previous value. Basic Dictionary Behavior Let's see what happens when we try to add a duplicate key ? a = {'foo': 42, 'bar': 55} print("Original dictionary:", a) # Assigning new value to existing key a['foo'] = 100 print("After reassignment:", a) Original dictionary: {'foo': 42, 'bar': 55} After reassignment: {'foo': 100, 'bar': 55} Checking for Duplicate Keys During ...

Read More

What is the Keys property of Hashtable class in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 166 Views

The Keys property of the Hashtable class in C# returns an ICollection containing all the keys in the hashtable. This property is useful for iterating through all keys or performing operations on the key collection without accessing the values. Syntax Following is the syntax for accessing the Keys property − public virtual ICollection Keys { get; } Return Value The Keys property returns an ICollection object that contains all the keys in the hashtable. The order of keys is not guaranteed as hashtables do not maintain insertion order. Using Keys Property to ...

Read More

C# program to find common elements in three arrays using sets

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 609 Views

In C#, you can find common elements in three arrays efficiently using HashSet collections. A HashSet provides fast lookups and set operations, making it ideal for finding intersections between collections of data. The HashSet class offers built-in methods like IntersectWith() that can perform set operations directly, eliminating the need for complex loops and comparisons. Syntax Following is the syntax for creating a HashSet from an array − var hashSet = new HashSet(array); Following is the syntax for finding intersection using IntersectWith() − hashSet1.IntersectWith(hashSet2); hashSet1.IntersectWith(hashSet3); Finding ...

Read More

C# Enum IsDefined Method

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 3K+ Views

The Enum.IsDefined method in C# determines whether a specified value exists within a given enumeration. It returns true if the value is found, either as an integral value or its corresponding string name, and false otherwise. Syntax Following is the syntax for the Enum.IsDefined method − public static bool IsDefined(Type enumType, object value) Parameters enumType − The type of the enumeration to check against. value − The value to look for in the enumeration (can be an integer or string). Return Value Returns true if the specified value exists ...

Read More

Chaining comparison operators in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 693 Views

C# supports chaining comparison operators based on operator associativity and precedence. When multiple operators of the same precedence appear in an expression, they are evaluated according to their associativity rules, typically left-to-right. Understanding how comparison operators chain together is crucial for writing correct conditional expressions and avoiding logical errors in your code. Syntax Following is the basic syntax for chaining comparison operators − variable1 == variable2 == variable3 variable1 != variable2 != variable3 The evaluation follows left-to-right associativity − (variable1 == variable2) == variable3 How Operator Chaining Works ...

Read More

What is the difference between public, static and void keywords in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 14K+ Views

The public, static, and void keywords in C# have specific meanings and are commonly seen together in the Main method of any C# program. Understanding these keywords is essential for C# programming as they control access, memory allocation, and return behavior of methods. The Main method serves as the entry point for all C# programs, defining what a class does when executed. Syntax Following is the typical syntax of the Main method showing all three keywords − public static void Main(string[] args) { // program execution starts here } ...

Read More

Comparing enum members in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 2K+ Views

To compare enum members in C#, you can use the Enum.CompareTo() method or standard comparison operators. Enum comparison is based on the underlying numeric values assigned to each enum member. Syntax Following is the syntax for using CompareTo() method − enumValue1.CompareTo(enumValue2) Following is the syntax for using comparison operators − enumValue1 == enumValue2 // equality enumValue1 > enumValue2 // greater than enumValue1 < enumValue2 // less than Return Value The CompareTo() method returns − Negative value if the first enum is ...

Read More
Showing 21–30 of 810 articles
« Prev 1 2 3 4 5 81 Next »
Advertisements