Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8849573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:41:14+00:00 2026-06-14T12:41:14+00:00

I have a homework assignment where I need to do three-way conversion between decimal,

  • 0

I have a homework assignment where I need to do three-way conversion between decimal, binary and hexadecimal. The function I need help with is converting a decimal into a hexadecimal. I have nearly no understanding of hexadecimal, nonetheless how to convert a decimal into hex. I need a function that takes in an int dec and returns a String hex. Unfortunately I don’t have any draft of this function, I’m completely lost. All I have is this.

  public static String decToHex(int dec)
  {
    String hex = "";


    return hex;
  }

Also I can’t use those premade functions like Integer.toHexString() or anything, I need to actually make the algorithm or I wouldn’t have learned anything.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:41:15+00:00Added an answer on June 14, 2026 at 12:41 pm

    One possible solution:

    import java.lang.StringBuilder;
    
    class Test {
      private static final int sizeOfIntInHalfBytes = 8;
      private static final int numberOfBitsInAHalfByte = 4;
      private static final int halfByte = 0x0F;
      private static final char[] hexDigits = { 
        '0', '1', '2', '3', '4', '5', '6', '7', 
        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
      };
    
      public static String decToHex(int dec) {
        StringBuilder hexBuilder = new StringBuilder(sizeOfIntInHalfBytes);
        hexBuilder.setLength(sizeOfIntInHalfBytes);
        for (int i = sizeOfIntInHalfBytes - 1; i >= 0; --i)
        {
          int j = dec & halfByte;
          hexBuilder.setCharAt(i, hexDigits[j]);
          dec >>= numberOfBitsInAHalfByte;
        }
        return hexBuilder.toString(); 
      }
    
      public static void main(String[] args) {
         int dec = 305445566;
         String hex = decToHex(dec);
         System.out.println(hex);       
      }
    }
    

    Output:

    1234BABE
    

    Anyway, there is a library method for this:

    String hex = Integer.toHexString(dec);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need little help on a homework assignment. I have to create a 10
For my homework assignment, I need to implement Horners Algorithm for converting between bases.
I have a homework assignment where I need to take input from a file
Hi I have a homework assignment where I need to implement an intersection of
I have been given a homework assignment where I need to create a captcha
I have an assignment on 8086 assembly (this is homework), I need to display
Hello I have a homework assignment where I need to read two matrix .txt
I have a homework assignment where I'm supposed to find the cheapest airfares between
I have a homework assignment in which I need to compute the edit distance
For my homework assignment I need to write the body of this function, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.