C
C#8mo ago
Muhammad

❔ ✅ denary -> binary

using System.Data;

static void Main(string[] args)
{
string ans = AddBinary(1, 2);
Console.WriteLine(ans);
Console.ReadLine();
}
static string AddBinary(int a, int b)
{
string string_combiner = "";
int number = a + b;

for (int i = 1; i <= 32; i++)
{

int powered_number = (int)Math.Pow(number, i);
if (number % powered_number == 0)
{
string_combiner.Insert(0, "1");
}


else
{
string_combiner.Insert(0, "0");
}

}

return string_combiner;

}
using System.Data;

static void Main(string[] args)
{
string ans = AddBinary(1, 2);
Console.WriteLine(ans);
Console.ReadLine();
}
static string AddBinary(int a, int b)
{
string string_combiner = "";
int number = a + b;

for (int i = 1; i <= 32; i++)
{

int powered_number = (int)Math.Pow(number, i);
if (number % powered_number == 0)
{
string_combiner.Insert(0, "1");
}


else
{
string_combiner.Insert(0, "0");
}

}

return string_combiner;

}
35 Replies
Muhammad
Muhammad8mo ago
what am i doing wrong im tired
Jimmacle
Jimmacle8mo ago
why do you have one method responsible for both adding numbers and converting them to binary? and is this specifically something you have to write yourself or do you just need it formatted in binary?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
no just a personal project idk how to convert to binary that's why
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
i don't think so
Jimmacle
Jimmacle8mo ago
as of .NET 8 it looks like there's a string format specifier for binary 1234.ToString("B")
Muhammad
Muhammad8mo ago
meaning?
Jimmacle
Jimmacle8mo ago
meaning if you use .NET 8 you can just do that
Muhammad
Muhammad8mo ago
ToString meaning add B to the beginning of the string
Jimmacle
Jimmacle8mo ago
no meaning "convert 1234 to binary"
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
TeBeCo
REPL Result: Success
int value = 12353429;
Convert.ToString(value, 2)
int value = 12353429;
Convert.ToString(value, 2)
Result: string
101111000111111110010101
101111000111111110010101
Compile: 492.113ms | Execution: 23.424ms | React with ❌ to remove this embed.
MODiX
MODiX8mo ago
TeBeCo
isn't there method in dotnet to change a number fom a base to another ?
Quoted by
<@689473681302224947> from #denary -> binary (click here)
React with ❌ to remove this embed.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
WTH 💀
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle8mo ago
i try to forget Convert exists
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
int value = 12353429; b_value = Convert.ToString(value, 2);
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
? mind showing the hex thing
Jimmacle
Jimmacle8mo ago
you mean the base64 conversions?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
mind correcting as in 16 = 10 F0
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
what did i do wrong here tho what's 2?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
ah
MODiX
MODiX8mo ago
TeBeCo
REPL Result: Success
byte[] array = { 0x64, 0x6f, 0x74, 0x63, 0x65, 0x74 };

string hexValue = Convert.ToHexString(array);
Console.WriteLine(hexValue);

/*Output:
646F74636574
*/
byte[] array = { 0x64, 0x6f, 0x74, 0x63, 0x65, 0x74 };

string hexValue = Convert.ToHexString(array);
Console.WriteLine(hexValue);

/*Output:
646F74636574
*/
Console Output
646F74636574
646F74636574
Compile: 627.605ms | Execution: 94.631ms | React with ❌ to remove this embed.
MODiX
MODiX8mo ago
TeBeCo
REPL Result: Success
string hexString = "8E2";
int num = Int32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(num);
//Output: 2274
string hexString = "8E2";
int num = Int32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(num);
//Output: 2274
Console Output
2274
2274
Compile: 563.441ms | Execution: 32.679ms | React with ❌ to remove this embed.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Muhammad
Muhammad8mo ago
thank you 🙂 !close
Accord
Accord8mo ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Entity framework migration problemI have problem with creating the migration. I get this error "The seed entity for entity type 'AuthoCS00012 The type is defined in an assembly that is not referenced. But that assembly it is referenceOtherwise if I remove that reference I am getting more than 100 errors, the moment I add that refereI need little help trying to make something like that clicks for this game to help me build somethinHello, I can't get this program to click as it jumps i try and try it won't click idk why but my py❔ EFCore Interceptor problemIn the MS documentation I see they're using the SaveChanges interceptor as: ```csharp public async V❔ Is Entity Framework still worth usingIt has been a good 10 years or so since I used EF. From what I recall, it was good for code first an❔ question around testing techniques and ressources for itgood evening everyone i recently started learning more in depth about testing tdd ddd and correspon❔ asp.net core sessions data set lost on refreshguys i have a big problem which i've been trying to solve for the past few days, so i'm using ASP.NE✅ Getting Error 400: Invalid Hostname when trying to access application in Docker containerHello, I have a .net 7 application running inside a Docker container. The .NET application has an en❔ Swashbuckle remove SwaggerDocI have two swagger docs and I want one of them to be entirely removed (from the drop down too) based✅ Localhost HTTP Error 503Hi - so I'm working on a group university project (I say group but there's only 2 of us working on i