Results 1 to 18 of 18
Thread: C++ ( )
Hybrid View
-
9th June 2017 19:32 #1
C++ ( )
, , binary, 0 -> 1 1 -> 0 binary decimal number.
binary, . flip(); , . . :
: 7, 00000111 -> 1 -> 0 0 -> 1 11111000 248.Code:// convert.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <bitset> #include <string> using namespace std; int main() { int num = 0; string binary; cout << "Please enter a decimal number: " << endl; cin >> num; binary = bitset<8>(num).to_string(); cout << "The dec in binary number is: " << binary << endl; return 0; }Last edited by Decrux; 9th June 2017 at 20:00.
-
9th June 2017 20:47 #2
? . bitset<>::flip() , . .
-
9th June 2017 22:51 #3
, ... .
http://www.cplusplus.com/reference/bitset/bitset/flip/
2 ...
.. ...
http://imgur.com/a/9aRY6Last edited by Decrux; 9th June 2017 at 23:02.
-
9th June 2017 23:16 #4
:
Code:cout << "The dec in flipped binary number is: " << binary.flip() << endl;
-
9th June 2017 23:19 #5?: 7, 00000111 -> 1 -> 0 0 -> 1 11111000 248.
8 unsigned char
int 32 32 -8
~7Last edited by ined; 9th June 2017 at 23:20.
ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173
-
9th June 2017 23:48 #6, , . .. NOP (No OPeration).Code:
bitset<8>(binary).flip();
, :
- bitset<8> binary.
- flip().
- 1 .
binary.
@postscriptum , a :
Code:string flipped = bitset<8>(binary).flip().to_string(); cout << flipped << endl;
Last edited by pe6o; 9th June 2017 at 23:50.
-
10th June 2017 00:08 #7
!
:
, :Code:#include "stdafx.h" #include <iostream> #include <bitset> #include <string> using namespace std; int main() { int num = 0; unsigned long result = 0; string binary; cout << "Please enter a decimal number: " << endl; cin >> num; binary = bitset<8>(num).to_string(); cout << "The dec in binary number is: " << binary << endl; string flipped = bitset<8>(binary).flip().to_string(); cout << "Flipped binary number: " << flipped << endl; result = bitset<8>(flipped).to_ulong(); cout << "Result: " << result << endl; return 0; }
, .Code:string flipped = bitset<8>(binary).flip().to_string();
, .Last edited by Decrux; 10th June 2017 at 00:09.
-
18th June 2017 14:13 #8
. C++ Bjarne Stroustrup:
The C++ Programming Language Programming -- Principles and Practice Using C++
, ( 400., ). , up-to-date . , ?
-
25th June 2017 00:07 #9ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in