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

  • Home
  • SEARCH
  • 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 786219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:00:23+00:00 2026-05-14T21:00:23+00:00

I discovered something odd that I can’t explain. If someone here can see what

  • 0

I discovered something odd that I can’t explain. If someone here can see what or why this is happening I’d like to know. What I’m doing is taking an unsigned short containing 12 bits aligned high like this:

1111 1111 1111 0000

I then want to shif the bits so that each byte in the short hold 7bits with the MSB as a pad. The result on what’s presented above should look like this:

0111 1111 0111 1100

What I have done is this:

unsigned short buf = 0xfff;
//align high
buf <<= 4;

buf >>= 1;
*((char*)&buf) >>= 1;

This gives me something like looks like it’s correct but the result of the last shift leaves the bit set like this:

0111 1111 1111 1100

Very odd. If I use an unsigned char as a temporary storage and shift that then it works, like this:

unsigned short buf = 0xfff;
buf <<= 4;

buf >>= 1;
tmp = *((char*)&buf);
*((char*)&buf) = tmp >> 1;

The result of this is:

0111 1111 0111 1100

Any ideas what is going on here?

  • 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-14T21:00:24+00:00Added an answer on May 14, 2026 at 9:00 pm

    Yes, it looks like char is signed on your platform. If you did *((unsigned char*)&buf) >>= 1, it would work.

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

Sidebar

Related Questions

Today I discovered something that makes me sad: objects of type System.Generic.Collections.List don't have
I've discovered this idiom recently, and I am wondering if there is something I
I was debugging something and discovered some strangeness in JavaScript: alert(1=='') ==> false alert(0=='')
I discovered that one of the tables of a legacy db I'm working on
We recently discovered that the Google Maps API does not play nicely with SSL.
Today I discovered that my fresh installation of Apache HTTP Server is able to
I've discovered that any time I do the following: echo '<a href=http:// title=bla>huzzah</a>'; I
I discovered template metaprogramming more than 5 years ago and got a huge kick
I discovered to have some problem to fully understand callbacks scoping when trying to
I recently discovered the genshi.builder module. It reminds me of Divmod Nevow's Stan module.

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.