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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:14:56+00:00 2026-06-08T14:14:56+00:00

Came across this question in one of the interview samples. A 16-byte aligned allocation

  • 0

Came across this question in one of the interview samples. A 16-byte aligned allocation has already been answered in How to allocate aligned memory only using the standard library?

But, I have a specific question in the same regarding the mask used to zero down the last 4 bits. This mask “~0F” has been used such that the resulting address is divisible by 16. What should be done to achieve the same for 32-byte alignment/divisibility?

  • 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-08T14:14:59+00:00Added an answer on June 8, 2026 at 2:14 pm

    First, the question you referred to is 16-byte alignment, not 16-bit alignment.

    Regarding your actual question, you just want to mask off 5 bits instead of 4 to make the result 32-byte aligned. So it would be ~0x1F.

    To clarify a bit:

    To align a pointer to a 32 byte boundary, you want the last 5 bits of the address to be 0. (Since 100000 is 32 in binary, any multiple of 32 will end in 00000.)

    0x1F is 11111 in binary. Since it’s a pointer, it’s actually some number of 0’s followed by 11111 – for example, with 64-bit pointers, it would be 59 0’s and 5 1’s. The ~ means that these values are inverted – so ~0x1F is 59 1’s followed by 5 0’s.

    When you take ptr & ~0x1F, the bitwise & causes all bits that are &’ed with 1 to stay the same, and all bits that are &’ed with 0 to be set to 0. So you end up with the original value of ptr, except that the last 5 bits have been set to 0. What this means is that we’ve subtracted some number between 0 and 31 in order to make ptr a multiple of 32, which was the goal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this question in one Interview. Please help me in getting the
I came across this question on an interview questions thread. Here is the question:
I am preparing for my interview and came across this question: Consider that i
I came across this in an java interview earlier. It was one of the
I came across this post , which reports the following interview question: Given two
I came across this question in an interview. Any number with 3 in its
I came across this question on an interview website - We are given 4
Possible Duplicate: Help with algorithm problem from SPOJ Came across this interview question. Given
Came across this one while browsing the response to another question on SO (
I came across this question after searching for a ODBC or JDBC. To my

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.