#Help me understand
37 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
!hw
Welcome to Together C & C++ :wave:
We won't do your homework for you (#rules) but we are happy to help you learn and point you in the right direction.
Please send what you have so far and ask a specific question.
!howto ask
Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.
State your problem clearly and provide all necessary details:
- the relevant portion of your code, or all of it
- the expected output
- the actual output (or the full error)
:trophy: Gold Standard: Minimal Reproducible Example
Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:
- Compiler Explorer for most C and C++ snippets
- OnlineGDB for interaction, debugging
:no_entry: Do not post screenshots, let alone photos of your screen!
how do i convert a string of characters to binary in c? for example: aaa, into a long binary
There are certainly easier options like Python which they also allow you to use
That's your assignment...
idk how to code in python
my assignment is to calculate the check sum for a string of characters in 8bit, 16bit, and 32bit checksum bit size
however i’m stuck on how to actually convert the string of characters into binary
I mean, each of the characters of a string is just a number already
like e.g. 'a' is 97 and '\n' is 10
i tried adding just the ascii values of each character and then converting it into hexadecimal, however it was wrong. we have to add them through their binary numbers and ignore and overflow
Can you draw out what you want to happen on paper? I.e. could you calculate the checksum for a small string by hand?
That's for the 8-bit checksum, no?
yes that is
Okay, that's the easy one, you just add each character to a uint8_t sum variable and that's your checksum.
How about for the 16-bit checksum? Can you do that on paper for the string "abc\n"?
but how do i have the binary for each character get added. because if i were to add it it would add its ascii value
it would add its ascii value
Yes? That's exactly what the "binary value" is
The computer only sees a number, and the translation from and to a character is purely for us humans
and we have defined the ASCII table to standardize which number should translate to which character (and vice versa)
so if i were to add the character it would add its binary?
yes
The computer only knows binary numbers.
Just like with the translation from numbers to characters (and the other way around), the computer also translates all the binary numbers into decimal ones again purely because us humans suck at reading binary
then how would i ensure that it doesn’t take in the overflow, and instead cuts it off
wdym? "Doesn't take in the overflow"
in the example i showed in the picture, i didn’t count into the sum the 1 that carries over
well, how would you?
that’s the issue i’m having ;-;
I mean. That should be your main issue
Also your assignment from time to time references your lecture and expects some knowledge of your lecture to properly understand how they want the checksum to be implemented
Where are you stuck?