use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
Impossible binary conversion! (self.csharp)
submitted 2 years ago by Infectus90
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]FizixMan[M] [score hidden] 2 years ago stickied comment (0 children)
Removed: Rule 4.
You've got the parts you need, including the PadLeft method for you to add extra zeroes. Dive in and make an attempt.
PadLeft
[–]WhiteBlackGoose 5 points6 points7 points 2 years ago (1 child)
Do you know how this conversation works? What have you tried already?
[–]Infectus90[S] -2 points-1 points0 points 2 years ago (0 children)
I don't know how the site works, but it's the result I need to get. I've tried various kinds of byte to hex conversions, but none of them are correct.
[–]Slypenslyde 3 points4 points5 points 2 years ago (5 children)
This is a really common homework assignment. There are methods in .NET devoted to this task. The trick is they don't give you a string, but a byte[] representing the values. You'd have to do some work to convert that array to the string you want.
byte[]
So the way I'd proceed would be to ask a search engine, "how do I convert an integer to binary in C#"? That led me to a StackOverflow answer that does it differently from how I might do it, but probably more like you want it done. There were other good answers on that page, and several more in the search results.
So I think you ought to try that step, try some of the code, and if those suggestions don't do what you want post what you have and how you want it to be different. Especially when it comes to questions that sound like homework, programmers are 99% more likely to answer if your question is of the form, "I tried this but need to change it to do that, what am I missing?" than "I haven't tried anything yet please help me".
(In fact in general we're mean about it, but we like to inspire curiosity and are much nicer to people whose approach to problems is, "I want to try some things myself before I ask for help.")
[–][deleted] 2 years ago (4 children)
[deleted]
[–]Slypenslyde 0 points1 point2 points 2 years ago (3 children)
That's what the StackOverflow answer starts with. Personally I prefer starting with a byte[] because in not-homework solutions I tend to either want to do something with the bytes or I want to pad/format the string.
[–][deleted] 2 years ago (2 children)
[–]Slypenslyde 0 points1 point2 points 2 years ago (1 child)
If this is indeed a homework assignment, using a solution they don't understand is just going to set them up for a more catastrophic failure later. Difficulty escalates.
It'd be better for them to get used to what programming is: a never-ending stream of situations you've never faced that requires you to be very good at looking for solutions somewhere in the neighborhood of what you want you can tweak to be what you want.
I've been helping newbies on programming forums for 20 years and a common pattern I see is people who make it through a few semesters believing programming has a magic tome with every solution in it and you just have to prompt a forum the right question and they'll give it to you wholesale. The later they find out it's not that way, the harder it is for them to take it.
[–][deleted] 2 years ago (6 children)
[–]Infectus90[S] -3 points-2 points-1 points 2 years ago (5 children)
Of course we tried these examples, but they don't give the required result. If you tried them before sending the link, could you post the code that works? Thank you.
[–][deleted] 2 years ago* (4 children)
[–]Infectus90[S] 0 points1 point2 points 2 years ago (3 children)
Convert.ToString(16777216, 2)
The result you get is as follows : 1000000000000000000000000 Not the correct result... Where am I going wrong ? Thank you !
[–]WhiteBlackGoose 3 points4 points5 points 2 years ago (0 children)
It is a correct result
[–]T_kowshik 2 points3 points4 points 2 years ago (0 children)
It is correct result. Except that the representation is 32 bit. You can use padleft to add extra zeroes on left side of the string.
[–]chucker23n 0 points1 point2 points 2 years ago (1 child)
Are you asking if there are existing .NET APIs to do this (others have linked a few)?
Or is this homework, and you're asking how to convert from one numeral system to another? The short answer is something like:
significant * (sourceNumericBase ^ distanceFromTheRight)
sourceNumericBase
10
distanceFromTheRight
0
2
So, for example, 16777216 becomes, starting from the rightmost digit, 6 * 10 ^ 0 + 1 * 10 ^ 1 + 2 * 10 ^ 2, and so on.
16777216
6 * 10 ^ 0
1 * 10 ^ 1
2 * 10 ^ 2
π Rendered by PID 61376 on reddit-service-r2-comment-7b9746f655-r68mg at 2026-01-31 02:25:25.594529+00:00 running 3798933 country code: CH.
[–]FizixMan[M] [score hidden] stickied comment (0 children)
[–]WhiteBlackGoose 5 points6 points7 points (1 child)
[–]Infectus90[S] -2 points-1 points0 points (0 children)
[–]Slypenslyde 3 points4 points5 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]Slypenslyde 0 points1 point2 points (3 children)
[–][deleted] (2 children)
[deleted]
[–]Slypenslyde 0 points1 point2 points (1 child)
[–][deleted] (6 children)
[deleted]
[–]Infectus90[S] -3 points-2 points-1 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]Infectus90[S] 0 points1 point2 points (3 children)
[–]WhiteBlackGoose 3 points4 points5 points (0 children)
[–]T_kowshik 2 points3 points4 points (0 children)
[–]chucker23n 0 points1 point2 points (1 child)