Converting Decimal Numbers to Hexadecimal Notation in C#, Exercises of Javascript programming

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

2021/2022

Uploaded on 06/03/2022

jj-toraja
jj-toraja 🇵🇭

5 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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-2
//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);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Run

Partial preview of the text

Download Converting Decimal Numbers to Hexadecimal Notation in C# and more Exercises Javascript programming in PDF only on Docsity!

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