New Posts  All Forums:Forum Nav:

C++ converting  

post #1 of 4
Thread Starter 
Well im trying to covert :

Binary to decimal
decimal to binary
Decimal to hex ( Done)
Hex to decimal

Anyone want to help?
You guys maybe asking why am I doing this all again (if you helped me before) but what happened was I stopped making a calculator then I testing peoples code on google then played around and accidentally saved and closed :S

So I decided to do it all over again. Completed most things but im really stupid at decimal and binary stuff frown.gif
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
post #2 of 4
Thread Starter 
A user did help
Code:
std::string dec2bin( unsigned n )
{
    const size_t size = sizeof( n ) * 8;
    char result[ size ];
    unsigned index = size;

    do 
    {
        result[ --index ] = '0' + ( n & 1 );
    } 
    while ( n >>= 1 );

    return std::string( result + index, result + size );
}

but does not seem to work :S
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
Work PC
(4 items)
 
Home PC
(4 items)
 
 
CPUMotherboardGraphicsRAM
4770k Asus SABERTOOTH Z87 290 16 trident  
CPUMotherboardGraphicsRAM
8350 gigabyte 990fxa 660 16gb trident 
  hide details  
post #3 of 4
You can use std::bitset
Code:
std::string dec2bin(int n)
{
        std::bitset<sizeof(n)* 8> bs(n);
        return bs.to_string();
}
buka
(17 items)
 
  
buka
(17 items)
 
  
post #4 of 4
I think your original thread is better suited for this discussion. Sorry smile.gif

http://www.overclock.net/t/1472053/c-calculator-help
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
#well
(19 items)
 
Lenovo L530
(8 items)
 
 
CPUMotherboardGraphicsRAM
Intel Core i7 4770k Gigabyte Z87X-UD4H XFX Radeon HD 6950 Corsair CMX8GX3M2A2000C9 
Hard DriveHard DriveOptical DriveCooling
Samsung EVO 840 Hitachi HDS722020ALA330 Generic DVD±RW Burner Noctua NH-D14 
OSMonitorMonitorKeyboard
Windows 8.1 Dell U2711 LG W2453 Ducky DK9008 Overclock.net Edition, Cherry MX B... 
PowerCaseMouseMouse Pad
Corsair TX850 Antec Three Hundred Corsair Raptor M40 QPAD HeatoN M 
AudioAudioAudio
E-MU Tracker|pre Beyerdynamic DT-770 250 Ohm AntLion ModMIc 
CPUGraphicsRAMRAM
Intel Ivy Bridge 3210M Intel HD 4000 Graphics Soldered Corsair Vengeance  
Hard DriveOptical DriveOSMonitor
500GB DVD-+RW Windows 7 Professional 1600x900 
  hide details  
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
This thread is locked