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
SDL_SETROWSTRETCHCOD(3) 					   Manual Pages 					   SDL_SETROWSTRETCHCOD(3)

NAME
SDL_SetRowStretchCode, SDL_PutRowStretchCode, SDL_RunRowStretchCode, SDL_StretchRow1, SDL_StretchRow2, SDL_StretchRow3, SDL_StretchRow4 - (src/SDL_stretchcode.h) SYNOPSIS
#include <SDL_stretch.h> unsigned char* SDL_SetRowStretchCode(int src_w, int dst_w, int bpp); unsigned char* SDL_PutRowStretchCode(unsigned char* buffer, int buflen, int src_w, int dst_w, int bpp); void SDL_RunRowStretchCode(unsigned char* buffer, unsigned char* src, unsigned char* dst); void SDL_StretchRow1(Uint8 *src, int src_w, Uint8 *dst, int dst_w); void SDL_StretchRow2(Uint16 *src, int src_w, Uint16 *dst, int dst_w); void SDL_StretchRow3(Uint8 *src, int src_w, Uint8 *dst, int dst_w); void SDL_StretchRow4(Uint32 *src, int src_w, Uint32 *dst, int dst_w); DESCRIPTION
The SetRowStretchCode is a wrapper around PutRowStretchCode that uses the Adress and Size of the shared SDL_TheRowStretchCode buffer. The PutRowStretchCode will fill the given buffer with an assembler stream that should be called with SDL_RunRowStretchCode. The assembler stream is usually faster as all the scale decisions are done in advance of the execution. This helps when a RunCode is done multiple times with the same src_w/dst_w/bpp pair. All the pixel-get and pixel-set calls are unrolled in that buffer. Therefore, the buffer should be big enough - as a rule of thumb use a buffer of size (src_w+dst_w)*5 If PutCode or SetCode fails, a NULL is returned and SDL_SetError. Otherwise, the start adress of the machine code buffer is returned, which is also the input argument of PutCode and RunCode. If SDL_SetRowStretchCode fails, the SDL_StretchRow1 function must be used instead. The SDL_StretchRow1 function and its cousins are singular routines that work in a tight loop to scale a single row. The number specifies the byte-width of each pixel (it is not a bit-width!). SDL_stretch 0.3.1 SDL_SETROWSTRETCHCOD(3)
All times are GMT -4. The time now is 05:16 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy