Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Hexadecimal to Octal#316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
varunu28 merged 4 commits intoTheAlgorithms:masterfromThe-TJ:patch-1
Dec 6, 2017
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Create HextoDec.java
Program that converts Hexadecimal numbers to decimal.
  • Loading branch information
@The-TJ
The-TJ authoredNov 17, 2017
commit37838f6237aaa79b882f1476634495af093893e6
49 changes: 49 additions & 0 deletionsConversions/HexToOct.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
/* Java Program - Convert Hexadecimal to Octal
Author - Tanmay Joshi*/

import java.util.Scanner;

public class HexToOct
{
public static int hex2decimal(String s)
{
String str = "0123456789ABCDEF";
s = s.toUpperCase();
int val = 0;
for (int i = 0; i < s.length(); i++)
{
char a = s.charAt(i);
int n = str.indexOf(a);
val = 16*val + n;
}
return val;
}
public static void main(String args[])
{
String hexadecnum;
int decnum, i=1, j;
int octnum[] = new int[100];
Scanner scan = new Scanner(System.in);

System.out.print("Enter Hexadecimal Number : ");
hexadecnum = scan.nextLine();

// first convert hexadecimal to decimal

decnum = hex2decimal(hexadecnum);

// convert decimal to octal

while(decnum != 0)
{
octnum[i++] = decnum%8;
decnum = decnum/8;
}

System.out.print("Equivalent Octal Number is :\n");
for(j=i-1; j>0; j--)
{
System.out.print(octnum[j]);
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp