Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Carla Schneider <carla_schn@proton.me> |
|---|---|
| Newsgroups | ger.ct |
| Subject | Re: Chatbots wirklich nuetzlich |
| Date | 2024-08-21 10:53 +0200 |
| Organization | Mausgrau |
| Message-ID | <66C5AAF9.4D05735D@proton.me> (permalink) |
| References | <Chatbot-20240817145919@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
>
> Für meine Programmierprojekte ist der Internet-Chatbot sehr
> nützlich. Er erzeugt Quellcode, den ich gar nicht oder erst nach
> stundenlangen Recherchen schreiben könnte, in einer Sekunde. Der
> Code ist in der Regel auch einsatzfähig und läuft. Manchmal hat
> er Bugs, aber auch bei deren Beseitigung hilft der Chatbot.
Hier ein Beispiel das ich ausprobiert habe:
Eingabe:
I want do store 2bit unsigned integer values in an uint8 array,
write me the macros GET and PUT for a C Program to do this
Ausgabe:
#include <stdint.h>
#define PUT(arr, index, value) do { \
uint8_t byte_index = (index) / 4; \
uint8_t bit_offset = ((index) % 4) * 2; \
(arr)[byte_index] &= ~(0x3 << bit_offset); \
(arr)[byte_index] |= ((value) & 0x3) << bit_offset; \
} while (0)
#define GET(arr, index) ( \
(((arr)[((index) / 4)] >> (((index) % 4) * 2)) & 0x3) \
)
int main() {
uint8_t array[2] = {0}; // Example array of size 2 bytes, which can store 8 2-bit values
PUT(array, 0, 1); // Put value 1 at index 0
PUT(array, 1, 2); // Put value 2 at index 1
PUT(array, 2, 3); // Put value 3 at index 2
PUT(array, 3, 0); // Put value 0 at index 3
PUT(array, 4, 1); // Put value 1 at index 4
// Get and print values
printf("Value at index 0: %u\n", GET(array, 0));
printf("Value at index 1: %u\n", GET(array, 1));
printf("Value at index 2: %u\n", GET(array, 2));
printf("Value at index 3: %u\n", GET(array, 3));
printf("Value at index 4: %u\n", GET(array, 4));
return 0;
}
Das Programm enthaelt einen Fehler der erst bei einem Array ab der
Laenge 256 auffaellt.
Ich haette ihm wohl sagen muessen dass ich ein Array
der groesse 1024GB im Sinn hatte so dass index alle moeglichen 32bit
Integer werte durchlaufen kann...
Back to ger.ct | Previous | Next | Find similar | Unroll thread
Re: Chatbots wirklich nuetzlich Carla Schneider <carla_schn@proton.me> - 2024-08-21 10:53 +0200
csiph-web