New Posts  All Forums:Forum Nav:

C++ calculator help

post #1 of 12
Thread Starter 
So if you dont know recently I've been learning C++. In the past few threads I created I told everyone I was going to make a calculator tongue.gif.

I seen the windows calculator and wanted to copy some ideas (dont sue me microsoft lol) but I was thinking about converting then numbers into decimal, hexadecimal, binary. Anyone want to help me on doing this

I found some things but still cant get around my head. If its not possible then leave it tongue.gif I was just making the calculator for fun smile.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  
Reply
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  
Reply
post #2 of 12
I wouldn't mind helping you, but i tend to avoid GUI's with C++. I prefer C# for simple stuff like that, my reasons are probably dumb, but whatever. BUT, in any case, go for it. If you run into any problems, just post it on here, and we can get you sorted out.
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #3 of 12
Quote:
Originally Posted by AnnoyinDemon View Post

So if you dont know recently I've been learning C++. In the past few threads I created I told everyone I was going to make a calculator tongue.gif.

I seen the windows calculator and wanted to copy some ideas (dont sue me microsoft lol) but I was thinking about converting then numbers into decimal, hexadecimal, binary. Anyone want to help me on doing this

I found some things but still cant get around my head. If its not possible then leave it tongue.gif I was just making the calculator for fun smile.gif

You have a few choices:

Windows Forms with C++/CLI (easiest, but C++/CLI has a learning curve as its C++ combined with the managed CLI - if you were doing this I would say to pick C# as the language)
MFC/ATL (C++ class wrappers around Win32 APIs).
Pure Win32 (ouch!)

I suppose there's some cross platform GUI toolkits you can use too.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #4 of 12
Quote:
Originally Posted by AnnoyinDemon View Post

I seen the windows calculator and wanted to copy some ideas (dont sue me microsoft lol)

Don't worry. You wouldn't be the first one to do it; I've seen trojan malware pose as calc.exe biggrin.gif
Quote:
Originally Posted by AnnoyinDemon View Post

but I was thinking about converting then numbers into decimal, hexadecimal, binary. Anyone want to help me on doing this

Well if you use C functions like printf() and scanf(), then there really isn't any "conversion" to do if you just choose the correct string formatting (i.e. %d for decimal, %x for hex, etc.)

I don't think they have one for binary, though. Some advice for that if you were to implement it yourself might be to brush up on bit manipulation. For example, if you have an 8-bit number like 243 = 0b11110011, then you could left-shift a 1 for every bit (loop 1 << i or something like that) and do an AND mask. If your result is > 0, then there is a 1 in that position.

An example run:

11110011
00000001
________
00000001 (mark a '1')

11110011
00000010
________
00000010 (mark a '1')

11110011
00000100
________
00000000 (mark a '0')

etc.

And then put it all the chars together in the end. There are probably other/better algorithms for this, but it's a start.
post #5 of 12
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 );
}

biggrin.gif
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #6 of 12
Quote:
Originally Posted by The Hundred Gunner View Post

Don't worry. You wouldn't be the first one to do it; I've seen trojan malware pose as calc.exe biggrin.gif
Well if you use C functions like printf() and scanf(), then there really isn't any "conversion" to do if you just choose the correct string formatting (i.e. %d for decimal, %x for hex, etc.)

I don't think they have one for binary, though. Some advice for that if you were to implement it yourself might be to brush up on bit manipulation. For example, if you have an 8-bit number like 243 = 0b11110011, then you could left-shift a 1 for every bit (loop 1 << i or something like that) and do an AND mask. If your result is > 0, then there is a 1 in that position.

An example run:

11110011
00000001
________
00000001 (mark a '1')

11110011
00000010
________
00000010 (mark a '1')

11110011
00000100
________
00000000 (mark a '0')

etc.

And then put it all the chars together in the end. There are probably other/better algorithms for this, but it's a start.

Oh god, i didnt even think of the bitwize math that you can do. Every time i made a calc program as an example for test driven development, i made functions like subtract(X,Y) by doing X-Y. I never even thought of even doing the bitwize style. My favorite bitnotation calculation is if you multiply any number by 2. Just add a 0 at the end =)
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
Zev's Comp
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5-2500K Sandy Bridge 3.3GHz GIGABYTE GA-Z68X-UD3H-B3 LGA 1155 Intel Z68 HDM... GeForce GTX 750 Ti G.SKILL Ripjaws X Series 8GB 
Hard DriveHard DriveHard DrivePower
1TB HDD 64GB SSD (Used for SRT) 500 GB. Antec BP550 Plus 550W Continuous Power ATX12V V... 
Case
COOLER MASTER ELITE 335 RC-335-KKN1-GP Black S... 
  hide details  
Reply
post #7 of 12
Quote:
Originally Posted by Mrzev View Post

Oh god, i didnt even think of the bitwize math that you can do. Every time i made a calc program as an example for test driven development, i made functions like subtract(X,Y) by doing X-Y. I never even thought of even doing the bitwize style. My favorite bitnotation calculation is if you multiply any number by 2. Just add a 0 at the end =)

I'm pretty sure THG was advertising an algorithm to convert decimal to binary, not to do bitwise math.
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
Ol' Sandy
(28 items)
 
"Zeus"
(12 items)
 
Elite Preview
(6 items)
 
CPUMotherboardGraphicsRAM
Intel Xeon E3-1230v3 Gigabyte GA-Z97X-UD5H-BK MSI Gaming GTX 980 Kingston 32GB (4x8) 
Hard DriveHard DriveHard DriveHard Drive
Plextor PX-256M5S 256GB Samsung EVO 1TB Hitachi HDS721010CLA332 Hitachi HDS723020BLA642 
Hard DriveHard DriveHard DriveOptical Drive
Hitachi HDS723020BLA642 Hitachi HUA722010CLA330 WDC WD10EARS-00Z5B1 TSSTcorp CDDVDW SH-S223B 
CoolingCoolingOSMonitor
Phanteks PH-TC14PE with TY-140's Lamptron FCv5 (x2) Windows 8 Pro 64-bit Dell U2412M 
MonitorMonitorMonitorKeyboard
Dell U2412M Dell U2212HM Dell U2713HM Topre Realforce 87UB | Ducky DK9087 G2 Pro 
PowerCaseMouseMouse Pad
Corsair AX-750 Corsair Obsidian 650D Logitech G700 XTRAC Ripper XXL 
AudioAudioAudioAudio
Beyerdynamic DT-770 Pro 250ohm Schiit Bifrost DAC Schiit Asgard 2 HiVi Swan M50W 2.1 
CPUMotherboardRAMHard Drive
Intel Xeon E5-2620 Super Micro X9SRL-F-B 128GB 1333MHz LSI 9271-8i 
OSPowerCase
VMware ESXi 5.5 SeaSonic SS-400FL2 Fractal Define R3 
CPUMotherboardGraphicsRAM
Intel Core i5-3437U HP EliteBook Folio 9470m  Intel HD Graphics 4000  16GB DDR3 SDRAM 
Hard DriveOS
256GB SSD Windows 10 Insider Preview 
  hide details  
Reply
post #8 of 12
Quote:
Originally Posted by Mrzev View Post

Oh god, i didnt even think of the bitwize math that you can do. Every time i made a calc program as an example for test driven development, i made functions like subtract(X,Y) by doing X-Y. I never even thought of even doing the bitwize style. My favorite bitnotation calculation is if you multiply any number by 2. Just add a 0 at the end =)

The following pseudocode doesn't handle unsigned or float numbers, but it overviews the basics (note: the negative numbers represent the 2's complement). Since it is going to be used on a per-byte basis, the loop can be sped up significantly by unrolling 8 times per loop (set the counter to the sizeof(input number type) instead of bit length).

If you don't want the 2's complement, take the 1's complement (NOT) and add 1 to get the positive version then add the neg sign.
Things are easy for unsigned. reduce the array size by one and do the same thing.
Adding support for float requires splitting the number into sign bit, exponent, and mantissa. Insert the sign, insert the exponent, insert the 'e', then insert the implied 1 and the mantissa. This gets harder when you support multiple float sizes as each uses different quantities of exponent and mantissa bits (this needs to be hard coded).
Code:
//the extras are for string terminator and sign
char array[BIT_LENGTH + 2]

if leftmost bit is a 1:
  array[0] = '-'
else
  array[0] = '+'

//set a pointer (temp_ptr) to the end of the array (working right to left)
char *temp_ptr = array[last element];
//set final char to null then decrement
*temp_ptr-- = '\0';

//we're working backward (right to left) because it's more efficient
for (i = number of bits; i > 0; i--):
  //shift the input integer eg. 10011011 --> 01001101
  //then AND with 0000 0001
  //we shift the input instead of the 1 because so we always get
  //an answer of 0000 0000 or 0000 0001
  //we then add 0011 0000 (0x30 in hex) to turn the 1 or 0 into the char equivalent
  //finally, we decrement temp_ptr
  *temp_ptr-- = ((in_number >>= 1) & 1) + 0x30;


Edited by hajile - 3/7/14 at 4:51pm
post #9 of 12
Thread Starter 
Quote:
Originally Posted by tompsonn View Post

You have a few choices:

Windows Forms with C++/CLI (easiest, but C++/CLI has a learning curve as its C++ combined with the managed CLI - if you were doing this I would say to pick C# as the language)
MFC/ATL (C++ class wrappers around Win32 APIs).
Pure Win32 (ouch!)

I suppose there's some cross platform GUI toolkits you can use too.

Yes, I started using C++/CLI mid half way but I started trying out QT lol. Im just messing with a few programs to see how each of them at like. I might even try win32. R+ and thank you for a reply!

Quote:
Originally Posted by The Hundred Gunner View Post

Don't worry. You wouldn't be the first one to do it; I've seen trojan malware pose as calc.exe biggrin.gif
Well if you use C functions like printf() and scanf(), then there really isn't any "conversion" to do if you just choose the correct string formatting (i.e. %d for decimal, %x for hex, etc.)

I don't think they have one for binary, though. Some advice for that if you were to implement it yourself might be to brush up on bit manipulation. For example, if you have an 8-bit number like 243 = 0b11110011, then you could left-shift a 1 for every bit (loop 1 << i or something like that) and do an AND mask. If your result is > 0, then there is a 1 in that position.

An example run:

11110011
00000001
________
00000001 (mark a '1')

11110011
00000010
________
00000010 (mark a '1')

11110011
00000100
________
00000000 (mark a '0')

etc.

And then put it all the chars together in the end. There are probably other/better algorithms for this, but it's a start.

My calc program shows its a virus even when at times I do a simple cout function lol. I have seen a code somthing similar like that tongue.gif ! R+ and thank you for a reply!
Quote:
Originally Posted by tompsonn View Post

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 );
}

biggrin.gif
Thanks DUDE! Well I made one but its a LOT longer then this and it doesnt let me do negative numbers ;/ lol Will try your one out + its shorter biggrin.gif R+ and thank you for a reply!
Quote:
Originally Posted by hajile View Post

The following pseudocode doesn't handle unsigned or float numbers, but it overviews the basics (note: the negative numbers represent the 2's complement). Since it is going to be used on a per-byte basis, the loop can be sped up significantly by unrolling 8 times per loop (set the counter to the sizeof(input number type) instead of bit length).

If you don't want the 2's complement, take the 1's complement (NOT) and add 1 to get the positive version then add the neg sign.
Things are easy for unsigned. reduce the array size by one and do the same thing.
Adding support for float requires splitting the number into sign bit, exponent, and mantissa. Insert the sign, insert the exponent, insert the 'e', then insert the implied 1 and the mantissa. This gets harder when you support multiple float sizes as each uses different quantities of exponent and mantissa bits (this needs to be hard coded).
Code:
//the extras are for string terminator and sign
char array[BIT_LENGTH + 2]

if leftmost bit is a 1:
  array[0] = '-'
else
  array[0] = '+'

//set a pointer (temp_ptr) to the end of the array (working right to left)
char *temp_ptr = array[last element];
//set final char to null then decrement
*temp_ptr-- = '\0';

//we're working backward (right to left) because it's more efficient
for (i = number of bits; i > 0; i--):
  //shift the input integer eg. 10011011 --> 01001101
  //then AND with 0000 0001
  //we shift the input instead of the 1 because so we always get
  //an answer of 0000 0000 or 0000 0001
  //we then add 0011 0000 (0x30 in hex) to turn the 1 or 0 into the char equivalent
  //finally, we decrement temp_ptr
  *temp_ptr-- = ((in_number >>= 1) & 1) + 0x30;


I just posted a second ago saying I cant do 2s compliment but hey you are my hero biggrin.gif R+ and thank you for a reply!!!!!!!!!!!


I like to thank everyone here that helped. This is awesome! I'm going to try to do hexadecimal :O Wish me luck !
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  
Reply
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  
Reply
post #10 of 12
Thread Starter 
Hexadecimal was easy

Just had


Code:
     int number;

        cin >>number;
        cout << "0x" << hex << number<< '\n';
        system("Pause");

Found one online just might make a few adjustments but seems alright.
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  
Reply
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  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming