Skip to content
Snippets Groups Projects
Commit 116c28c9 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Musterlösungen zu Aufgabe 4 der Klausur vom 29.1.2016

parent 0e14e0b5
No related branches found
No related tags found
No related merge requests found
Showing with 802 additions and 0 deletions
#include
#define aufgabe_4_width 14
#define aufgabe_4_height 14
static unsigned char aufgabe_4_bits[] = {
0x00, 0x00, 0x07, 0x03, 0x08, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13,
0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0x0e, 0x04, 0x09,
0x08, 0x04, 0x0f, 0x00, 0x03, 0x00, 0x00
};
void print_xbm_ascii(unsigned char *bitmap, int width, int height) {
for (int y = 0; y for (int x = 0; x int byte_index = (y * width + x) / 8;
int bit_index = x % 8;
int bit = (bitmap[byte_index] >> bit_index) & 1;
printf(bit ? "*" : " ");
}
printf("\n");
}
}
int main() {
print_xbm_ascii(aufgabe_4_bits, aufgabe_4_width, aufgabe_4_height);
return 0;
}
#include <stdio.h>
#include "aufgabe-4.xbm" // XBM-Datei einbinden
void print_xbm_ascii() {
for (int y = 0; y < aufgabe_4_height; y++) {
for (int x = 0; x < aufgabe_4_width; x++) {
int byte_index = ((y * aufgabe_4_width + 7) / 8 * 8 + x) / 8; // Byte-Index berechnen
int bit_index = x % 8; // Bit-Position innerhalb des Bytes
// Prüfen, ob das Bit gesetzt ist (LSB first)
if (aufgabe_4_bits[byte_index] & (1 << bit_index)) {
printf("*"); // Schwarzes Pixel
} else {
printf(" "); // Weißes Pixel
}
}
printf("\n");
}
}
int main() {
print_xbm_ascii();
return 0;
}
#include <stdio.h>
#include "aufgabe-4.xbm" // XBM-Datei einbinden
void print_xbm_ascii() {
for (int y = 0; y < aufgabe_4_height; y++) {
for (int x = 0; x < aufgabe_4_width; x++) {
int byte_index = (y * aufgabe_4_width + x) / 8; // Byte-Index berechnen
int bit_index = x % 8; // Bit-Position innerhalb des Bytes
// Prüfen, ob das Bit gesetzt ist (LSB first)
if (aufgabe_4_bits[byte_index] & (1 << bit_index)) {
printf("*"); // Schwarzes Pixel
} else {
printf(" "); // Weißes Pixel
}
}
printf("\n");
}
}
int main() {
print_xbm_ascii();
return 0;
}
\ No newline at end of file
#include <stdio.h>
/*
#define aufgabe_4_width 14
#define aufgabe_4_height 14
static unsigned char aufgabe_4_bits[] = {
0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13,
0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04,
0xf0, 0x03, 0x00, 0x00
};
*/
#include "aufgabe-4.xbm"
void print_ascii_art() {
for (int y = 0; y < aufgabe_4_height; y++) {
for (int x = 0; x < aufgabe_4_width; x++) {
int index = (y * ((aufgabe_4_width + 7) / 8)) + (x / 8);
unsigned char byte = aufgabe_4_bits[index];
if (byte & (1 << (7 - (x % 8)))) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
}
int main() {
print_ascii_art();
return 0;
}
#include <stdio.h>
#define aufgabe_4_width 14
#define aufgabe_4_height 14
static unsigned char aufgabe_4_bits[] = {
0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13,
0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04,
0xf0, 0x03, 0x00, 0x00
};
void print_ascii_art() {
for (int y = 0; y < aufgabe_4_height; y++) {
for (int x = 0; x < aufgabe_4_width; x++) {
int index = (y * (aufgabe_4_width / 8)) + (x / 8);
unsigned char byte = aufgabe_4_bits[index];
if (byte & (1 << (7 - (x % 8)))) {
printf("*");
} else {
printf(" ");
}
}
printf("\n");
}
}
int main() {
print_ascii_art();
return 0;
}
#include <stdio.h>
#include "aufgabe-4.xbm"
int main() {
unsigned char *bits = aufgabe_4_bits;
int width = aufgabe_4_width;
int bytes = (aufgabe_4_width + 7) / 8;
int height = aufgabe_4_height;
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
/*
* Calculate which byte in the bits array corresponds to this row
* and column. Each byte represents 8 columns.
*/
int bit_index = row * bytes + col / 8;
int bit_offset = col % 8;
if (bits[bit_index] & (1 << bit_offset)) {
printf("#");
} else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
#include <stdio.h>
#define aufgabe_4_width 14
#define aufgabe_4_height 14
static unsigned char aufgabe_4_bits[] = {
0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04, 0x08, 0x02, 0x10, 0x32, 0x13, 0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12, 0x12, 0xe4, 0x09, 0x08, 0x04, 0xf0, 0x03, 0x00, 0x00
};
int main() {
unsigned char *bits = aufgabe_4_bits;
int width = aufgabe_4_width;
int height = aufgabe_4_height;
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
/*
* Calculate which byte in the bits array corresponds to this row
* and column. Each byte represents 8 columns.
*/
int bit_index = (row * width + col) / 8;
int bit_offset = (row * width + col) % 8;
if ((bits[bit_index] >> (7 - bit_offset)) & 1) {
printf("#");
} else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
Mit englischer prompt: write me a c program that includes an .xbm
graphic file and plots that in the terminal.
include aufgabe-4.xbm. It looks like this:
#define aufgabe_4_width 14 #define aufgabe_4_height 14 static unsigned
char aufgabe_4_bits[] = { 0x00, 0x00, 0xf0, 0x03, 0x08, 0x04, 0x04,
0x08, 0x02, 0x10, 0x32, 0x13, 0x22, 0x12, 0x02, 0x10, 0x0a, 0x14, 0x12,
0x12, 0xe4, 0x09, 0x08, 0x04, 0xf0, 0x03, 0x00, 0x00 }
#include <stdio.h>
int main() {
unsigned char xbm_image[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
int width = 64; // The number of pixels per row
int height = 8; // The number of rows
for (int i = 0; i < height; i++) {
unsigned char *row_start = xbm_image + (i * (width / 8));
printf("Row %d: ", i + 1);
for (int j = 0; j < width; j++) {
int byte_index = j / 8;
int bit_index = j % 8;
unsigned char mask = 1 << bit_index;
if ((row_start[byte_index] & mask) != 0)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
This diff is collapsed.
loesung-4-deepseek-r1-14b-qwen-distill-q4_k_m-en-pg.c
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment