C
C#12mo ago
flesy_

I need Help with twos Complement

Hi Guys i need to write a program that transforms sbyte numbers in twos complement. Do you have any ideas on how to solve this problem?
36 Replies
ZacharyPatten
ZacharyPatten12mo ago
We won't do you homework for you. Please elaborate on what you have tried so far and we will try to guide you based on that what does your current code look like?
flesy_
flesy_OP12mo ago
can i send you my program? it does weird things.
Jimmacle
Jimmacle12mo ago
you can send it in this chat here
Pobiega
Pobiega12mo ago
$code
MODiX
MODiX12mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
flesy_
flesy_OP12mo ago
i did use paste.mod.gg can you please check it and if you know say what is wrong. Thank you
Jimmacle
Jimmacle12mo ago
you need to share the link
flesy_
flesy_OP12mo ago
BlazeBin - ainzxwelbkan
A tool for sharing your source code with the world!
flesy_
flesy_OP12mo ago
Did it work?
Jimmacle
Jimmacle12mo ago
yep i don't speak german though
flesy_
flesy_OP12mo ago
it doesnt really matter they are just explanations
Jimmacle
Jimmacle12mo ago
those are important when i'm trying to find one issue in an entire program 😛
flesy_
flesy_OP12mo ago
i can translate it wait a minute
Jimmacle
Jimmacle12mo ago
i don't understand the goal of the code, could you explain what the input and output is supposed to be?
flesy_
flesy_OP12mo ago
the input is a sByte number the program uses the decimal number and turns it into twos complement
Jimmacle
Jimmacle12mo ago
so you have a number and you just want the binary representation as output? where does the twos complement come in? that's an implementation detail of signed integers, it's not something you typically do by hand if you want the negative of a number you just multiply by -1 or negate it
flesy_
flesy_OP12mo ago
the task of the duty is to convert a decimal number in twos complement. He didn´t teach us how to convert it so i tried doing it by hand but it doesnt work.
Jimmacle
Jimmacle12mo ago
that's what i'm saying, it doesn't make sense because the computer already does that because that's how computers handle integers
Jimmacle
Jimmacle12mo ago
No description
flesy_
flesy_OP12mo ago
i think he wants us to explain how the twos complement works by converting it step by step If you cant help me no problem. I don´t know what he wants from me either.
Jimmacle
Jimmacle12mo ago
i mean, the manual process is pretty simple it just doesn't make sense to write a program to do it
flesy_
flesy_OP12mo ago
Can you show me the manual process? Would be really nice.
Jimmacle
Jimmacle12mo ago
to convert between positive and negative you just flip the bits then add 1 for example 1 -> 00000001 flip bits -> 11111110 add 1 -> 11111111 and to convert back to positive you just do the same thing again
flesy_
flesy_OP12mo ago
do you know a command to flip the bits?
Jimmacle
Jimmacle12mo ago
yes, bitwise NOT var flipped = ~value; y = ~x + 1 is functionally identical to y = x * -1
Omnissiah
Omnissiah12mo ago
maybe if they did this manually on a string representation of a number it would make sense, it would be educative i guess
Jimmacle
Jimmacle12mo ago
i did this by hand in college it makes sense that way, but a computer is already handling numbers in their binary representation anyway had to do IEEE 754 by hand too Harold
Omnissiah
Omnissiah12mo ago
that's a lot of bit juggling
flesy_
flesy_OP12mo ago
i think i am just dumb. It just doesn´t want to work. Smadge
Jimmacle
Jimmacle12mo ago
what isn't working?
flesy_
flesy_OP12mo ago
I don´t even know. Are there any other methodes to sort it by hand?#
MODiX
MODiX12mo ago
Jimmacle
for example 1 -> 00000001 flip bits -> 11111110 add 1 -> 11111111
Quoted by
React with ❌ to remove this embed.
Jimmacle
Jimmacle12mo ago
this is how you do it by hand
flesy_
flesy_OP12mo ago
how to convert a decimal number in bits
flesy_
flesy_OP12mo ago
ok thank you
Want results from more Discord servers?
Add your server