Sponsored Content
Full Discussion: C++ last bit of an image
Top Forums Programming C++ last bit of an image Post 302510270 by lamachejo on Saturday 2nd of April 2011 02:47:21 PM
Old 04-02-2011
C++ last bit of an image

Hi guys, I've been trying to find out what's wrong with the code, g++ doesn't prompt any error but it doesn't do what I want it to do, and after looking at it over and over I can't find anything wrong with it. The code its quite simple:

I need to save the last bit of every position on the vector and to form a word, for example:
buffer[0] has 00110011
buffer[1] has 11000010

I need to get the last bit and form a letter every 8 bits to decode the sentence.


buffer is a dinamic vector that has the image info loaded on it, cadena is where I want to store the "decoded " letters

Code:
 void revelarPGM (char* &cadena,unsigned char buffer[]) { 
 int binario=0;			
 int j=0;	
 cadena=new char[50000];
 for (int i=0; i<262144; i++) {
     if((buffer[i]&1)==0){ // HERE i use the AND operator to get the last bit, if it is
           binario=(binario<<1);  // A 0, i just shift once
     }else{   
	   binario=(binario<<1);  //IF it is a 1, i shift and add a 1 with the OR
  	   binario=(binario|1);    
     }
   if (i%7==0) {               // WHEN i get 8 bits i store the letter in cadena
          cadena[j]=binario;
          j++;
	  cout << binario << endl;
          binario=0;
  }
 }
 for (int i=0; i<300; i++)
cout << cadena[i];  // cout to see the words i stored.
delete [] cadena;
}

I hope I made myself clear. The problem is I am getting rubbish. But everytime i look at the code, it seems alright to me.

edit: tried to edit the title since i forgot to add it was C++ but it wont allow me now.

Last edited by lamachejo; 04-02-2011 at 03:52 PM..
 

4 More Discussions You Might Find Interesting

1. Programming

copying or concatinating string from 1st bit, leaving 0th bit

Hello, If i have 2 strings str1 and str2, i would like to copy/concatenate str2 to str1, from 1st bit leaving the 0th bit. How do i do it? (2 Replies)
Discussion started by: jazz
2 Replies

2. Red Hat

boot the 32 bit kernel on a 64 bit PPC Linux machine?

Hi all, I'm looking to cover a corner case for an upcoming test cycle. Is there a way to boot a RedHat Advanced Server 4 (update 3) installed on a Power PC machine to use a 32 bit kernel? This would be similar to what is done here -> https://www.unix.com/aix/26204-aix-platform.html I've done... (0 Replies)
Discussion started by: philrau
0 Replies

3. Shell Programming and Scripting

How to handle 64 bit arithmetic operation at 32 bit compiled perl interpreter?H

Hi, Here is the issue. From the program snippet I have Base: 0x1800000000, Size: 0x3FFE7FFFFFFFF which are of 40 and 56 bits. SO I used use bignum to do the math but summing them up I always failed having correct result. perl interpreter info, perl, v5.8.8 built for... (0 Replies)
Discussion started by: rrd1986
0 Replies

4. Windows & DOS: Issues & Discussions

Which version of Windows Vista to install with a product key? 32-bit or 64-bit?

Hello everyone. I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)
Discussion started by: milhan
4 Replies
fixup_datafile(3alleg4) 					  Allegro manual					   fixup_datafile(3alleg4)

NAME
fixup_datafile - Fixes truecolor images in compiled datafiles. Allegro game programming library. SYNOPSIS
#include <allegro.h> void fixup_datafile(DATAFILE *data); DESCRIPTION
If you are using compiled datafiles (produced by the dat2s and dat2c utilities) on a platform that doesn't support constructors (currently any non GCC-based platform), or if the datafiles contain truecolor images, you must call this function once after your set the video mode that you will be using. This will ensure the datafiles are properly initialised in the first case and convert the color values into the appropriate format in the second case. It handles flipping between RGB and BGR formats, and converting between different color depths when- ever that can be done without changing the size of the image (ie. changing 15<->16-bit hicolor for both bitmaps and RLE sprites, and 24<->32-bit truecolor for RLE sprites). Note that you can only call this once and expect it to work correctly, because after the call the DATAFILE you fixed up is permanently con- verted to whatever is the current component ordering for your screen mode. If you call fixup_datafile again, the function assumes you have a freshly loaded datafile. It cannot "undo" the previous conversion. If your program supports changing resolution and/or color depth during runtime, you have two choices: either call fixup_datafile() just once and hope that the component ordering and bit depth doesn't change when the screen mode changes (unlikely). Or, you can reload your datafiles when the screen mode changes. SEE ALSO
set_gfx_mode(3alleg4), set_color_conversion(3alleg4) Allegro version 4.4.2 fixup_datafile(3alleg4)
All times are GMT -4. The time now is 01:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy