Results 1 to 18 of 18

Thread: C++ ( )

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Decrux's Avatar
    Join Date: Aug:2016
    Location: .
    Posts: 562

    C++ ( )

    , , binary, 0 -> 1 1 -> 0 binary decimal number.
    binary, . flip(); , . . :
    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;
    }
    : 7, 00000111 -> 1 -> 0 0 -> 1 11111000 248.
    Last edited by Decrux; 9th June 2017 at 20:00.

  2. #2
    Banned pe6o's Avatar
    Join Date: Jan:2002
    Location: Sofia
    Posts: 1,263
    ? . bitset<>::flip() , . .

  3. #3
    Registered User Decrux's Avatar
    Join Date: Aug:2016
    Location: .
    Posts: 562
    Last edited by Decrux; 9th June 2017 at 23:02.

  4. #4
    Registered User postscriptum's Avatar
    Join Date: Mar:2006
    Location: Shinra Labs
    Posts: 644
    :
    Code:
    cout << "The dec in flipped binary number is: " << binary.flip() << endl;

  5. #5
    Registered User ined's Avatar
    Join Date: Nov:2006
    Location: Varna
    Posts: 1,078
    : 7, 00000111 -> 1 -> 0 0 -> 1 11111000 248.
    ?

    8 unsigned char

    int 32 32 -8

    ~7
    Last 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

  6. #6
    Banned pe6o's Avatar
    Join Date: Jan:2002
    Location: Sofia
    Posts: 1,263
    Code:
    bitset<8>(binary).flip();
    , , . .. NOP (No OPeration).
    , :
    1. bitset<8> binary.
    2. flip().
    3. 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.

  7. #7
    Registered User Decrux's Avatar
    Join Date: Aug:2016
    Location: .
    Posts: 562
    !
    :
    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.

  8. #8
    Registered User Decrux's Avatar
    Join Date: Aug:2016
    Location: .
    Posts: 562
    . C++ Bjarne Stroustrup:
    The C++ Programming Language Programming -- Principles and Practice Using C++
    , ( 400., ). , up-to-date . , ?

  9. #9
    Registered User hateras's Avatar
    Join Date: Jan:2011
    Location: Kronos III
    Posts: 1,028
    ASRock B550M Pro 4; Ryzen R5 3600; 2x16 GiB G.SKILL Aegis 3200; 1TB Samsung QVO 960 + 3TB Seagate IronWolf; Zalman Z1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |