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 7178769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:59:12+00:00 2026-05-28T16:59:12+00:00

Hy guys! I have the following problem: I need to hash an unsigned byte

  • 0

Hy guys!

I have the following problem:
I need to hash an unsigned byte in Java which is(would be…) between 0-255.
The main problem is that java doesnt have an unsigned Byte type at all.
I found a workaround for this, and used int instead of byte with a little modification.

The main problem is: Java.securitys Messagedigest.digest function only accepts byte array types, but i would need to give it an int array.

Anybody has a simpe workaround for this?
I was looking for a third party sha-1 function, but didnt found any. Nor any sample code.

So basically what i need:
I have an unsigned byte value for example: 0xFF and need to get the following sha1 hash: 85e53271e14006f0265921d02d4d736cdc580b0b

any help would be greatly appreciated.

  • 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-05-28T16:59:13+00:00Added an answer on May 28, 2026 at 4:59 pm

    It’s important to understand that there is no difference between signed and unsigned bytes with respect to their representation. Signedness is about how bytes are treated by arithmetic operations (other than addition and subtraction, in the case of 2’s complement representation).

    So, if you use bytes for data storage, all you need is to make sure that you treat them as unsigned when converting values to bytes (use explicit cast with (byte), point 1) and from bytes (prevent sign extension with & 0xff, point 2):

    public static void main(String[] args) throws Exception {    
        byte[] in = { (byte) 0xff }; // (1)
        byte[] hash = MessageDigest.getInstance("SHA-1").digest(in);
        System.out.println(toHexString(hash));
    }
    
    private static String toHexString(byte[] in) {
        StringBuilder out = new StringBuilder(in.length * 2);
        for (byte b: in)
            out.append(String.format("%02X", b & 0xff)); // (2)
        return out.toString();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey Guys, i have created the following Menu Structure: <div id=menu> <ul> <li><a href=#>Main
Hei guys, I have the following problem: As I can see those arrows are
Following problem: I would like to build a little clipboard with jQuery. I have
Hey guys, I have a problem with the following table: CREATE TABLE [dbo].[CA]( [Id]
I have a quite inconvenient problem. Say that I have the following functions function
Hey guys, i have the following problem: 1 process executes a very large query
Can you guys help me figure this out? I have the following JavaScript snippet:
guys i have arrays in which i have to match this kind of text
I have two schemas. 1.Schema A 2.Schema B I need to do following. I
EDIT: The main problem seemed to be that I was just doing Add Existing

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.