
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A c# code example for converting decimal numbers to their hexadecimal notation. The code uses a for loop to perform the conversion and prints the result to the console. This example can be useful for students and developers who need to understand how to work with number systems in c#.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Learn Python C# Online Compiler
Main.cs Output
// Online C# Editor for free // Write, Edit and Run your C# code using C# Online Compiler
//Rivas, Joy B. //BSIT III- //Write a program that converts a given number from decimal to hexadecimal notation. using System;
public class HelloWorld { public static void Main(string[] args) { Console.Write("Decimal number: "); int dec_num = int.Parse(Console.ReadLine()); int j = dec_num; int d = 0; for (int i = j; i > 0; i = i / 16) { int temp = i % 16; if (temp < 10) temp = temp + 48; else temp = temp + 55; d = d * 100 + temp; } Console.Write($"The hexadecimal of {dec_num} is "); for (int k = d; k > 0; k = k / 100) { int result = k % 100; Console.Write("{0}", (char)result); } } }
Run