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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:40:33+00:00 2026-05-20T12:40:33+00:00

I am trying to use implement the LSB lookup method suggested by Andrew Grant

  • 0

I am trying to use implement the LSB lookup method suggested by Andrew Grant in an answer to this question: Position of least significant bit that is set

However, it’s resulting in a segmentation fault. Here is a small program demonstrating the problem:

#include <iostream>

typedef unsigned char Byte;

int main()  
{  
    int value = 300;  
    Byte* byteArray = (Byte*)value;  
    if (byteArray[0] > 0)  
    {  
        std::cout<< "This line is never reached. Trying to access the array index results in a seg-fault." << std::endl;  
    }  
    return 0;  
}  

What am I doing wrong?
I’ve read that it’s not good practice to use ‘C-Style’ casts in C++. Should I use reinterpret_cast<Byte*>(value) instead? This still results in a segmentation fault, though.

  • 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-20T12:40:34+00:00Added an answer on May 20, 2026 at 12:40 pm

    Use this:

    (Byte*) &value;
    

    You don’t want a pointer to address 300, you want a pointer to where 300 is stored. So, you use the address-of operator & to get the address of value.

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

Sidebar

Related Questions

I am trying to use the answer of a preceding question to implement a
I would like to implement the method User.calculate_hashed_password . I'm trying to use the
I'm trying to use this excellent example to implement dropping virtual files into Windows
I'm trying to use boost::signal to implement a callback mechanism, and I'm getting a
I’m trying to implement a dictionary for use with WCF. My requirements are: actual
I'm trying to use SQLAlchemy to implement a basic users-groups model where users can
i'm trying to use jquery to implement a portlet/widget style interface, with 3 columns
Hi I am trying to use C to implement a simple struct: 2 boxes,
I am trying to use Test Driven Development to implement my signal processing library.
I'm trying to use Python and Numpy/Scipy to implement an image processing algorithm. The

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.