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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:25:39+00:00 2026-05-11T09:25:39+00:00

Hello I have a chunk of memory (allocated with malloc()) that contains bits (bit

  • 0

Hello I have a chunk of memory (allocated with malloc()) that contains bits (bit literal), I’d like to read it as an array of char, or, better, I’d like to printout the ASCII value of 8 consecutively bits of the memory.

I have allocated he memory as char *, but I’ve not been able to take characters out in a better way than evaluating each bit, adding the value to a char and shifting left the value of the char, in a loop, but I was looking for a faster solution. Thank you

What I’ve wrote for now is this:

for allocation:

char * bits = (char*) malloc(1); 

for writing to mem:

ifstream cleartext; cleartext.open(sometext); while(cleartext.good()) {      c = cleartext.get();      for(int j = 0; j < 8; j++)      {  //set(index) and reset(index) set or reset the bit at bits[i]         (c & 0x80) ? (set(index)):(reset(index));//(*ptr++ = '1'):(*ptr++='0');          c = c << 1;      }.. }.. 

and until now I’ve not been able to get character back, I only get the bits printed out using:

printf('%s\n' bits); 

An example of what I’m trying to do is:

input.txt contains the string ‘AAAB’

My program would have to write ‘AAAB’ as ‘01000001010000010100000101000010’ to memory (it’s the ASCII values in bit of AAAB that are 65656566 in bits)

Then I would like that it have a function to rewrite the content of the memory to a file.

So if memory contains again ‘01000001010000010100000101000010’ it would write to the output file ‘AAAB’.

  • 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. 2026-05-11T09:25:40+00:00Added an answer on May 11, 2026 at 9:25 am
    int numBytes = 512; char *pChar = (char *)malloc(numBytes); for( int i = 0; i < numBytes; i++ ){    pChar[i] = '8'; } 

    Since this is C++, you can also use ‘new’:

    int numBytes = 512; char *pChar = new char[numBytes]; for( int i = 0; i < numBytes; i++ ){    pChar[i] = '8'; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sending a message to nil won't cause an error, so… May 12, 2026 at 3:06 pm
  • Editorial Team
    Editorial Team added an answer Here's how: class Foo { static void someMethodThatTakesAHashMap(HashMap<String, String> map)… May 12, 2026 at 3:06 pm
  • Editorial Team
    Editorial Team added an answer A transaction should be a meaningful Unit Of Work. But… May 12, 2026 at 3:06 pm

Related Questions

I have a simple programs for socket client and server its not working over
I have a rails app moving along fairly well, but the fact that I'm
Are there any good books for a relatively new but not totally new *nix
Hello I have a number of crystal reports in my VS2008 project. I am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.