Igor🇺🇦
How to reverse a binary number and print its decimal form. Do we have to totally do it using arrays or is there any shortcut?
You can use https://en.cppreference.com/w/cpp/utility/bitset and https://en.cppreference.com/w/cpp/algorithm/reverse
olli
Is there any trick using bitwise operators??
Yes bitwise operators should be all you need. (assuming the number fits in a register) you can use 1 as a "mask" to always extract the lowest bit (or 128 to extract the highest) uint32_t mask = 1U; uint32_t lowests_bit = n & mask;
Manav
What is masking?
Bit masking is a simple way of getting out the specific bit value or manipulate them. You use bitwise operators like & and | for these. int a = 0b1111; // 15 int b = 0b1001; // 9 int mask = 0b0010; // 2 int get2ndBitOfA = a & mask; // 0b0010 int get2ndBitOfB = b & mask; // 0b0000
ברני
Hey again,I started a new task, writing 2d array of chars for the first time and I got an error that I don't understand, can you tell me what's wrong? I guess also the last funcion isn't working well but it tells me"Error C2040 'arr1': 'char [2][3]' differs in levels of indirection from 'char'"
ברני
thats the code: https://onlinegdb.com/HyOLtgTqD
ברני
on the site I sent it saying it conflicted
ברני
is it because of the defines?
Pooja
Happy thanks giving to all😊
klimi
Happy thanks giving to all😊
please, keep this chat on topic, thank you
Anonymous
https://codeforces.com/contest/1454/problem/C here is the problem. I'm having wrong answer in test case 2 in 10th query. It is giving answer 0 but when I run the code in my compiler it gives ans 1.Can you please tell me what the problem is. https://paste.ubuntu.com/p/Y3dWYkDVVN/
Roshan
thats the code: https://onlinegdb.com/HyOLtgTqD
Check the parameters of printMatrix() you sent arrays in place of rows and cols that are integers. Maybe this is your problem
ברני
Check the parameters of printMatrix() you sent arrays in place of rows and cols that are integers. Maybe this is your problem
I think I fixed the printMartix function but still same error... https://onlinegdb.com/BJbJx-pcP
Roshan
I think I fixed the printMartix function but still same error... https://onlinegdb.com/BJbJx-pcP
Now it's char rows which should have been int type. But I don't think this is what you want. It's about passing parameters I guess, IDK
ברני
Anonymous
apparently a simple delay is infact complex :(
UnknownBro
void deleteNode(Node *node) { // Your code here Node *ext,*p; ext->data=node->data; node->data=(node -> next)->data; (node->next)->data=ext->data; // move pointer to next p=node; p=p->next; node ->next=p ->next; node=p; delete node; }
Roshan
I think I fixed the printMartix function but still same error... https://onlinegdb.com/BJbJx-pcP
When I commented line 13, I get segmentation fault... Now that's your work
Roshan
When I commented line 13, I get segmentation fault... Now that's your work
@olli I guess this was the solution to @Barneysworld ... Is it though? Never used multidimensional arrays...
Roshan
ƪ(‾.‾“)┐ lol
olli
also the parameters passed are completely messed up..
ברני
Hey!!! You initialised the arrays as variables.
Ty!!! Now I have problem with the print function, 🤦‍♂ I'll check in Google how to print 2d char array
olli
@Barneysworld - There is no need to pass COLLS[1/2/3] since it's globally known, remove those parameters it's asking for trouble - You have chars and not strings, so using %s as format string is wrong - Have a function that prints ONE array and call it three times, instead of having a function that takes 3
olli
How do I call the function 3 times? I got confused again
I think you should get the basics before dealing with arrays. Something like what are functions, how are they called, what are parameters and so on...
olli
I see, ty anyway
otherwise void function() {} int main() { function(); // call 1st time function(); // call 2nd time // call function 10 more times for (int i = 0; i < 10; ++i) { function(); } }
olli
Here void function () {} Is this the way to create a custom function?
function is the example above is a function defined and used for demonstration purposes
I_Interface
Double kill.
Dima
I wanted to ban
Anonymous
I_Interface
Dima
sometimes I wonder if that guy was right about slav admins
Alex
Suck off.
why? this is ban, not eban
Alex
sometimes I wonder if that guy was right about slav admins
I am not sure about all slavs, russians for sure
Dima
What is eban?
slav cursing
Anonymous
What is eban?
electronic ban
Anonymous
(no)
Alex
by the way, I tried cppcheck - it found no errors in my code, only in boost headers and gperf code - so its useless for me
Anonymous
Clang-Tidy?
Alex
Did you try PVS Studio?
I was trying, but I realized its not free, so I gave up
Anonymous
Anonymous
best way to learn programming?
Alex
also I spent a lot of time to generate json for cppcheck with CMake. only latest version works without bugs. I am quite surprised about quality of this stuff
Anonymous
google.com
Yah I know but what practices should I do first?.
Roshan
Hi, I wanted to make a program that checks for the correct order of brackets. I've devised a way to do it - by incrementing the value of a variable when encountering an opening bracket and decrementing it when encountering closing bracket. Then I check if the number is equal to zero or not. But what if I've more than 1 type of bracket like (), {} and []. Do I have to make 3 vars for them??
Alex
Clang-Tidy?
no. after no warnings for my code +warnings for third party libraries(which is impossible to disable) with cppcheck(which is quite popular) , I am not sure it worths at all
Anonymous
can you recomend any project that should I start working on?
Alex
Yeah!! So any other way?
for () only check greater/equal than zero every time is closed and compare with zero at the end
Roshan
for () only check greater/equal than zero every time is closed and compare with zero at the end
That's what I did. But it's wrong approach, right? So any other way?
Anonymous
btw Is the problem wrong or not?.....
Roshan
for () its ok
What about )( or even {[}] ??