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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:14:31+00:00 2026-06-03T21:14:31+00:00

I was looking at hash functions the other day and came across a website

  • 0

I was looking at hash functions the other day and came across a website that had an example of one. Most of the code was easy to grasp, however this macro function I can’t really wrap my head around.

Could someone breakdown what’s going on here?

#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) +(uint32_t)(((const uint8_t *)(d))[0]))
  • 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-03T21:14:32+00:00Added an answer on June 3, 2026 at 9:14 pm

    Basically it gets the lower 16 bit of the 32 bit integer d

    lets break it down

    #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) +(uint32_t)(((const uint8_t *)(d))[0]))
    uint32_t a = 0x12345678;
    uint16_t b = get16bits(&a); // b == 0x00005678
    

    first we must pass the address of a to get16bits() or it will not work.

    (((uint32_t)(const uint8_t *)(d))[1])) << 8
    

    this first converts the 32 bit integer into an array of 8 bit integers and retrieves the 2 one.
    It then shifts the value by 8 bit so it and adds the lower 8 bits to it

    + (uint32_t)(((const uint8_t *)(d))[0]))
    

    In our example it will be

    uint8_t tmp[4] = (uint8_t *)&a;
    uint32_t result;
    result = tmp[1] << 8; // 0x00005600
    result += tmp[0]; //tmp[0] == 0x78
    // result is now 0x00005678
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a hash function that: Hashes textual strings well (e.g. few collisions)
I've been looking for a way to hash a given string in C# that
I've been looking around JQuery libraries for the URL hash, but found none that
I am looking for a PHP function that creates a short hash out of
I'm looking for a function that will generate an alphanumeric hash. Given a source
I am looking for a data structure that operates similar to a hash table,
I'm looking for a hash function that I can use to give uniform unique
I'm looking into hash and salting passwords using bcrypt in PHP. Can someone explain
I'm looking to create a hash with sha256 using openssl and C++. I know
I'm looking to create a simple brute-force password-cracker which will hash an input from

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.