Post No: 046 I recently explored two ways of doing bit manipulation: std::bitset and unsigned int. std::bitset feels easier to understand because it lets us work with bits in a clear and readable way. We can directly access, set, reset, and flip bits using simple functions. It is great when learning because the code looks clean and less error-prone. On the other hand, unsigned int gives much more flexibility. We can use bitwise operators like &, |, ^, ~, <<, and >> to perform powerful operations. It is fast and is used a lot. (Though I still don’t understand much on how, when and where to use unsigned int) But with that flexibility comes responsibility. When using unsigned int, we need to be very careful about bit positions, shifting values, masks, and understanding what each operation is doing. A small mistake can easily give wrong results and may be hard to debug. #CPP #Programming #Coding #SoftwareDevelopment #Learning #Beginners
Bit Manipulation with std::bitset and unsigned int in C++
More Relevant Posts
-
🚀 Day 9 of #100DaysOfCode Today’s LeetCode problem: Rotate Function (Medium) At first, the problem looks like a simulation — rotate the array every time and calculate the value again. But doing that would be O(n²)… not efficient. 💡 What is the question really asking? We are given an array and a function: F(k) = sum of (index * value) after rotating the array k times. We need to find the maximum value of F(k). 🧠 Key Insight (Game Changer): Instead of recalculating everything after each rotation, we observe a pattern: When we move from F(k) → F(k+1), 👉 Every element contributes +sum of array 👉 Except one element (the last rotated one), which contributes −n * value So the transition becomes: 👉 F(k+1) = F(k) + sum - n * last_element ⚡ Why this is powerful? Each element is effectively added once in the transitions, except the element that “wraps around” — it gets subtracted by n times. This reduces complexity from O(n²) → O(n) 🔥 #LeetCode #DSA #CodingJourney #ProblemSolving #100DaysOfCode #TUF #GFG #programming
To view or add a comment, sign in
-
-
🔀 Return codes hide your algorithm. Exceptions set it free. Look at a function full of return code checks. Somewhere inside all that nesting is the actual logic but you're reading two things at once. What happens when it works, and what happens when it doesn't. That's the real cost of return codes. They force two concerns into one structure, and neither one is readable on its own. Now look at the same function with exceptions: ✅ Verify the session ✅ Resolve the channel ✅ Moderate the content ✅ Broadcast to members Four steps. That's what the function does. The algorithm doesn't know about error handling. The error handling doesn't know about the algorithm. You can read either one without the other getting in the way. #CleanCode #Flutter #Dart #CodeQuality #SoftwareEngineering #Programming #DevTips #100DaysOfCode
To view or add a comment, sign in
-
-
Ever faced a memory leak… in code or in life? 😂 Post: In C, forgetting to free() memory leads to leaks. In life, forgetting to “let go” does the same. 🔹 Deleted the node 🔹 But memory still occupied That’s not just a bug… that’s emotional engineering 😄 👉 Lesson: Always clean up your pointers (and your past) #CProgramming #LinkedList #MemoryLeak #CodingHumor #SoftwareEngineering #EmbeddedSystems #DebuggingLife #TechMemes #ProgrammerLife
To view or add a comment, sign in
-
-
Most developers still confuse hashing, encryption, and encoding… and that’s a serious problem. Hashing is one-way — you can’t get the original data back. Encryption is reversible — but only with the right key. Encoding? It’s not security at all… just formatting. Build smart. Secure smarter. #BackendDevelopment #WebSecurity #SoftwareEngineering #CodingTips #DevelopersLife #Programming #SystemDesign #InfoSec #JavaDeveloper #codenroll #TechEducation #LearnToCode #DevCommunity
To view or add a comment, sign in
-
Claude Code Tip #15 / 100 — Stop letting quick questions eat your context window. Every message in Claude Code enters the conversation history. That question — and the answer — now occupies space for the rest of your session. Ask enough of them and you're burning context on noise. The /btw command fixes this. It opens a floating overlay where you ask a quick question. The answer shows up immediately — then disappears. It never enters the conversation history. Zero context cost. Use it for: "Why did you pick this approach?" or "What's the tradeoff here?" or "Is this the right pattern?" Get the clarity you need without paying for it in context overhead. Not every question deserves a permanent spot in your working memory. #ClaudeCode #AITools #DeveloperProductivity #Programming #CodingTips
To view or add a comment, sign in
-
I ran into an interesting behavior in Go that caught me off guard while working with slices. I created a slice from an array and then appended a value to the slice. Simple… right? But when I printed the original array, it was also modified. 😳 At first, I thought I had made a mistake. But I realized this is actually how Go slices work. Slices don’t copy data; they reference the same underlying array. So when you append to a slice within its capacity, Go reuses the same array, which can unintentionally modify the original data. That’s exactly what happened to me. Example scenario: Created a slice from the array Appended a new element Original array changed unexpectedly The fix: Create a new slice with separate memory before appending: newSlice := append([]int{}, oldSlice...) Lesson learned: Always be mindful of slice capacity when appending, especially when the original array should remain unchanged. Go’s slice internals are powerful, but they can also surprise you if you're not careful. #golang #softwareengineering #backenddevelopment #programming #developers #learning #coding
To view or add a comment, sign in
-
-
🚀 Getter and Setter Methods: Controlled Access to Private Attributes (Oop Concepts) Getter and setter methods (also known as accessors and mutators) provide a controlled way to access and modify private attributes. Getters return the value of a private attribute, while setters allow modification of the attribute's value. By using getters and setters, you can enforce validation rules, perform additional operations, or trigger events whenever an attribute is accessed or modified. This maintains encapsulation while still allowing controlled interaction with the object's internal state. #oopconcepts #programming #coding #tech #learning #professional #career #development
To view or add a comment, sign in
-
-
Last week, I was telling a friend about how great it would be to customize those Claude Code loading verbs that randomly appear after you prompt. Turns out I wasn’t the only one thinking this, since Anthropic actually made them configurable earlier this year. You can customize them entirely at a system, user, or project level via settings.json files (docs link in the comments). So naturally, I had to make a list of 100+ loading messages that would give any developer a mini heart attack when read. What would you customize yours to be? #claudecode #programming #softwaredeveloper
To view or add a comment, sign in
-
-
Real talk: You spend hours searching bugs because you don’t reproduce them first. You guess instead of confirming. Fix: - Reproduce the bug consistently - Note exact steps - Then debug from there If you can’t reproduce it, you can’t fix it. #Programming #Debugging #DevTips #WebDev
To view or add a comment, sign in
-
-
Real debugging process not shown in tutorials👀 Step 1: Does it work? → Yes: Don’t touch it. Ever. 🙏 → No: Panic gently. Step 2: Did you touch it? → Yes: Congratulations, you played yourself. → No: Suspicious… investigate anyway. Step 3: Can you blame someone else? → Yes: Problem solved. 🎉 → No: Welcome to character development. Step 4: Will you get into trouble? → Yes: Time to become a detective. 🕵️♂️ → No: *strategic silence activated* End result: Somehow… “No problems.” 😌 Behind every “simple fix” is a chaotic flowchart no one talks about. #Debugging #DeveloperLife #TechHumor #Programming #SoftwareEngineering #ITLife #CodeLife #Relatable #WorkHumor #ProblemSolving
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development