## Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]

Problem

Reverse digits of a 32-bit signed integer. When the reversed integer overflows return 0.

Feedback

Looking for any ways I can optimize this with modern c++ features overall. I hope my use of `const` correctness, exception handling, and assertions is implemented well here, please let me know. Is there any way I can use byte operations to reverse the int and keep track of the sign possibly?

Based on the submission feedback from LeetCode, is it safe to say that the time complexity is `O(n)` and space complexity is `O(n)`? If I can reduce the complexity in anyway would love to know! Thanks for the feedback in advance.

``#include <cassert> #include <climits> #include <stdexcept> #include <string>  class Solution  {     public:         int reverse(int i) {             bool is_signed = false;             if(i < 0) { is_signed = true; }              auto i_string = std::to_string(i);              std::string reversed = "";             while(!i_string.empty()) {                 reversed.push_back(i_string.back());                         i_string.pop_back();             }              try {                 i = std::stoi(reversed);             } catch (const std::out_of_range& e) {                 return 0;             }              if(is_signed) { i *= -1; }              return i;         } };  int main() {     Solution s;     assert(s.reverse(1) == 1);     assert(s.reverse(0) == 0);     assert(s.reverse(123) == 321);     assert(s.reverse(120) == 21);     assert(s.reverse(-123) == -321);     assert(s.reverse(1207) == 7021);         assert(s.reverse(INT_MAX) == 0);     assert(s.reverse(INT_MIN) == 0); } ``

## Converting a decimal to IEEE754 32-bit binary number

Convert 0.625 to IEEE754 32-bit binary number.

``0.625 x 2 = 1.250 0.250 x 2 = 0.500 0.500 x 2 = 1.000 ``

So,

``0.625 = 0.101   => 0.625 = 1.01 x 2^(-1) ``

So,

``S = 0 E = -1+127 = 126 => 01111110 M = 01 => 0100000 00000000 00000000  ``

I am confused with the mantissa part.

Would it be

``M = 01 => 0100000 00000000 00000000 ``

Or,

``M = 01 => 0000000 00000000 00000001 ``

?

## Installation of Teamviewer on Ubuntu 17.04 does not work (32-Bit machine)

I installed Ubuntu 17.04 on my 32-Bit notebook (previously used a WinXP-machine).
The notebook is a 32-Bit machine with 3GB RAM. Installtion of Ubuntu 17.04 worked fine.
I then tried to install Teamviewer (downloaded file teamviewer_14.1.18533_i386.deb), but constantly failed. During – incomplete – installation of Teamviewer I received messages about missing files/packages like

libqt5x11extras5
qt56-teamviewer
qml-module-qtquick-controls
qml-module-qtquick-dialogs

I had to remove Teamviewer from my system.
I am a rather unexperienced Ubuntu-user and wonder if someone can help me out with a description of steps to walk through when installing Teamviewer, especially how to install a .deb-file including all dependancies which might be necessary.

Thanks for your support. Best regards Michael

## What are some good books for learning 32bit MIPS single and multi cycle implementation?

I know of patterson and I don’t find it sufficiently detailed. It jumps from one thing to another without covering details. My architecture course in college consists of:

1. control and datapath of single and multi cycle implementation

2. pipelining and its implementation

3. hazards and fixes withimplementation

all implementation are in verilog. I’m not concerned about the implementation part. I just want to learn everything in detail from basics.

## How to install java 32bit version

I need a java jre 32bit version, how can I install it in my Ubuntu Server 18.10? I could only install the 64bit version of jvm.

## Breaking a 32-bit value into bytes for an ArrayList

I am very new to Java and its collections and I’m trying to figure out “best” way to populate an `ArrayList<Byte>` in Java. In particular, I’m trying to take a 32 bit number, divide it into bytes, and put it into big-endian order into the list. I’m not particularly interested in hyper-optimizing in this case; I’d rather the code be clean and readable.

I’ve got a couple issues that are obvious to me, but the biggest one is that I hate the fact that I am initializing the list with bogus values before I update them. But my choices seem to be that, or adding the elements in ascending order, which seems to make the code to extract the bytes significantly more complex.

Am I missing a better solution?

``public void Add32BitValue(int value) {     // Adding 4 elements first to the list, so that      // I can modify them so they'll be in big endian     // order.       // (The code to directly add them in big endian      // order seems much more complex.)     for (int i=0; i<4; i++) {         list.add((byte)0);     }      // Now that the elements are in the arraylist, they      // can be set.       for (int i = 3; i >= 0; i--) {         list.set(list.size() + i - 4, (byte)value);         value = value >> 8;     } } ``

I’m trying to setup an old education program my wife wants to try with our kids. Unfortunately, it was built in the Windows 3.1 / Windows 95 era. I’m running Fedora 29 x86_64 with Wine 4.0-0.3.rc2. I’ve setup a 32-bit prefix per https://wiki.winehq.org/FAQ#How_do_I_create_a_32_bit_wineprefix_on_a_64_bit_system.3F . When I run the setup.exe on the disk, it appears to install on the virtual Windows drive. When I run setup a second time, it gives the splash screen and provides the option to play. Clicking play produces the following:

``    Unhandled exception: page fault on read access to 0xffffffff in 16-bit code (1757:2782). In 16 bit mode. Register dump:  CS:1757 SS:1a4f DS:1a4f ES:0000 FS:0063 GS:006b  IP:2782 SP:d8ee BP:d9f4 FLAGS:0246(  R- --  I  Z- -P- )  AX:0000 BX:0000 CX:0052 DX:0000 SI:0000 DI:198b Stack dump: 0x1a4f:0xd8ee:  0000 198b 0007 ffdf 0007 ffcf 0007 ffdf 0x1a4f:0xd8fe:  0007 ffcf 0007 ffff 0007 1000 0000 0000 0x1a4f:0xd90e:  0000 0000 0000 0000 0000 0000 0000 100f 0349: sel=1a4f base=00780058 limit=0000dbff 16-bit rw- Backtrace: =>0 0x1757:0x2782 (0x1a4f:0xd9f4)   1 0x17af:0x18f2 (0x1a4f:0xd9fc)   2 0x17af:0x012d (0x1a4f:0xda50)   3 0x17c7:0x00df (0x1a4f:0xda6c)   4 0x17e7:0x00e2 (0x1a4f:0xda80)   5 0x17e7:0x02e2 (0x1a4f:0xda8c)   6 0x17e7:0x06fa (0x1a4f:0xda96)   7 0x171f:0x005f (0x1a4f:0xda9c)   8 0x1707:0x622f (0x1a4f:0xdaae)   9 0x1707:0x0854 (0x1a4f:0x0000) 0x1757:0x2782: lesw %es:0x0(%bx),%bx Modules: Module  Address         Debug info  Name (155 modules) ELF 6aa17000-6b400000   Deferred        shell32<elf>   \-PE  6aa30000-6b400000   \               shell32 ELF 7b400000-7b7fd000   Deferred        kernel32<elf>   \-PE  7b420000-7b7fd000   \               kernel32 ELF 7ba7b000-7bc00000   Deferred        libunistring.so.2 ELF 7bc00000-7bd41000   Deferred        ntdll<elf>   \-PE  7bc40000-7bd41000   \               ntdll ELF 7bea9000-7c000000   Deferred        libp11-kit.so.0 ELF 7c000000-7c005000   Deferred        <wine-loader> ELF 7c144000-7c400000   Deferred        libcrypto.so.1.1 ELF 7c447000-7c450000   Deferred        libffi.so.6 ELF 7c450000-7c4ca000   Deferred        libgmp.so.10 ELF 7c4ca000-7c4fd000   Deferred        libhogweed.so.4 ELF 7c4fd000-7c53c000   Deferred        libnettle.so.6 ELF 7c53c000-7c553000   Deferred        libtasn1.so.6 ELF 7c57d000-7c59d000   Deferred        libidn2.so.0 ELF 7c59d000-7c5af000   Deferred        libkrb5support.so.0 ELF 7c5af000-7c5ef000   Deferred        libcrypt.so.1 ELF 7c5ef000-7c605000   Deferred        libavahi-client.so.3 ELF 7c605000-7c7ea000   Deferred        libgnutls.so.30 ELF 7c7ea000-7c8db000   Deferred        libkrb5.so.3 ELF 7c8db000-7c935000   Deferred        libgssapi_krb5.so.2 ELF 7c935000-7c9d1000   Deferred        libcups.so.2 ELF 7c9d7000-7c9ef000   Deferred        toolhelp.dll16.so PE  7c9e0000-7c9ef000   Deferred        toolhelp.dll16 ELF 7c9ef000-7ca09000   Deferred        shell.dll16.so PE  7ca00000-7ca09000   Deferred        shell.dll16 ELF 7ca09000-7ca44000   Deferred        uxtheme<elf>   \-PE  7ca10000-7ca44000   \               uxtheme ELF 7ca44000-7ca85000   Deferred        winspool<elf>   \-PE  7ca50000-7ca85000   \               winspool ELF 7ca85000-7cacd000   Deferred        usp10<elf>   \-PE  7ca90000-7cacd000   \               usp10 ELF 7cacd000-7cc0c000   Deferred        comctl32<elf>   \-PE  7cae0000-7cc0c000   \               comctl32 ELF 7cc0c000-7cd00000   Deferred        comdlg32<elf>   \-PE  7cc10000-7cd00000   \               comdlg32 ELF 7ce02000-7ce21000   Deferred        libk5crypto.so.3 ELF 7ce21000-7ce3e000   Deferred        aclui<elf>   \-PE  7ce30000-7ce3e000   \               aclui ELF 7ce3e000-7ceb0000   Deferred        shlwapi<elf>   \-PE  7ce50000-7ceb0000   \               shlwapi ELF 7d008000-7d00e000   Deferred        libkeyutils.so.1 ELF 7d00e000-7d034000   Deferred        shcore<elf>   \-PE  7d020000-7d034000   \               shcore ELF 7d034000-7d0c0000   Deferred        libpcre2-8.so.0 ELF 7d0c0000-7d0e5000   Deferred        libgpg-error.so.0 ELF 7d0e5000-7d114000   Deferred        libselinux.so.1 ELF 7d114000-7d170000   Deferred        libblkid.so.1 ELF 7d170000-7d18a000   Deferred        libresolv.so.2 ELF 7d18a000-7d217000   Deferred        libvorbisenc.so.2 ELF 7d217000-7d248000   Deferred        libvorbis.so.0 ELF 7d248000-7d251000   Deferred        libogg.so.0 ELF 7d251000-7d2b5000   Deferred        libflac.so.8 ELF 7d2b5000-7d2d3000   Deferred        libgcc_s.so.1 ELF 7d2d3000-7d3b6000   Deferred        libgcrypt.so.20 ELF 7d3b6000-7d41e000   Deferred        libmount.so.1 ELF 7d41e000-7d43e000   Deferred        liblz4.so.1 ELF 7d43e000-7d4a0000   Deferred        libdbus-1.so.3 ELF 7d4a0000-7d528000   Deferred        libsndfile.so.1 ELF 7d528000-7d5e2000   Deferred        libsystemd.so.0 ELF 7d5e2000-7d674000   Deferred        libpulsecommon-12.2.so ELF 7d674000-7d79f000   Deferred        oleaut32<elf>   \-PE  7d690000-7d79f000   \               oleaut32 ELF 7d79f000-7d900000   Deferred        ole32<elf>   \-PE  7d7c0000-7d900000   \               ole32 ELF 7da01000-7da0f000   Deferred        libgsm.so.1 ELF 7da0f000-7da3b000   Deferred        liblzma.so.5 ELF 7da3b000-7da47000   Deferred        librt.so.1 ELF 7da47000-7da4e000   Deferred        libcap.so.2 ELF 7da4e000-7da6b000   Deferred        libice.so.6 ELF 7da6b000-7dac8000   Deferred        libpulse.so.0 ELF 7dacb000-7dada000   Deferred        libavahi-common.so.3 ELF 7dada000-7dadf000   Deferred        libcom_err.so.2 ELF 7dadf000-7daf9000   Deferred        commdlg.dll16.so PE  7daf0000-7daf9000   Deferred        commdlg.dll16 ELF 7dc01000-7dc09000   Deferred        libasyncns.so.0 ELF 7dc09000-7dc15000   Deferred        libsm.so.6 ELF 7dc15000-7dc42000   Deferred        winepulse<elf>   \-PE  7dc20000-7dc42000   \               winepulse ELF 7dc42000-7dc66000   Deferred        mmdevapi<elf>   \-PE  7dc50000-7dc66000   \               mmdevapi ELF 7dc66000-7dcee000   Deferred        rpcrt4<elf>   \-PE  7dc70000-7dcee000   \               rpcrt4 ELF 7dd2b000-7dd33000   Deferred        libxfixes.so.3 ELF 7dd33000-7dd40000   Deferred        libxcursor.so.1 ELF 7dd40000-7dd48000   Deferred        libxtst.so.6 ELF 7dd48000-7dd4d000   Deferred        libx11-xcb.so.1 ELF 7ddcb000-7de06000   Deferred        libexpat.so.1 ELF 7de06000-7de53000   Deferred        libfontconfig.so.1 ELF 7de53000-7de6d000   Deferred        libz.so.1 ELF 7de6d000-7deab000   Deferred        libpng16.so.16 ELF 7deab000-7debe000   Deferred        libbz2.so.1 ELF 7debe000-7df83000   Deferred        libfreetype.so.6 ELF 7df83000-7df98000   Deferred        libxi.so.6 ELF 7df98000-7dfc7000   Deferred        libxcb.so.1 ELF 7dfc7000-7e11e000   Deferred        libx11.so.6 ELF 7e11e000-7e134000   Deferred        libxext.so.6 ELF 7e16c000-7e200000   Deferred        winex11<elf>   \-PE  7e180000-7e200000   \               winex11 ELF 7e306000-7e315000   Deferred        libxrandr.so.2 ELF 7e315000-7e32b000   Deferred        win87em.dll16.so PE  7e320000-7e32b000   Deferred        win87em.dll16 ELF 7e32b000-7e341000   Deferred        sound.drv16.so PE  7e330000-7e341000   Deferred        sound.drv16 ELF 7e341000-7e3fd000   Deferred        winmm<elf>   \-PE  7e350000-7e3fd000   \               winmm ELF 7e3fd000-7e429000   Deferred        mmsystem.dll16.so PE  7e410000-7e429000   Deferred        mmsystem.dll16 ELF 7e429000-7e43f000   Deferred        mouse.drv16.so PE  7e430000-7e43f000   Deferred        mouse.drv16 ELF 7e43f000-7e455000   Deferred        keyboard.drv16.so PE  7e450000-7e455000   Deferred        keyboard.drv16 ELF 7e455000-7e46b000   Deferred        display.drv16.so PE  7e460000-7e46b000   Deferred        display.drv16 ELF 7e46b000-7e495000   Deferred        mpr<elf>   \-PE  7e470000-7e495000   \               mpr ELF 7e495000-7e4e6000   Deferred        user.exe16.so PE  7e4a0000-7e4e6000   Deferred        user.exe16 ELF 7e4e6000-7e51b000   Deferred        gdi.exe16.so PE  7e4f0000-7e51b000   Deferred        gdi.exe16 ELF 7e51b000-7e531000   Deferred        comm.drv16.so PE  7e520000-7e531000   Deferred        comm.drv16 ELF 7e531000-7e547000   Deferred        system.drv16.so PE  7e540000-7e547000   Deferred        system.drv16 ELF 7e547000-7e571000   Deferred        libtinfo.so.6 ELF 7e571000-7e5a1000   Deferred        libncurses.so.6 ELF 7e5a6000-7e5b4000   Deferred        libxrender.so.1 ELF 7e5b4000-7e5d9000   Deferred        imm32<elf>   \-PE  7e5c0000-7e5d9000   \               imm32 ELF 7e5d9000-7e68b000   Deferred        krnl386.exe16.so PE  7e5f0000-7e68b000   Deferred        krnl386.exe16 ELF 7e68b000-7e6a6000   Deferred        version<elf>   \-PE  7e690000-7e6a6000   \               version ELF 7e6a6000-7e723000   Deferred        advapi32<elf>   \-PE  7e6b0000-7e723000   \               advapi32 ELF 7e723000-7e856000   Deferred        gdi32<elf>   \-PE  7e730000-7e856000   \               gdi32 ELF 7e856000-7ea64000   Deferred        user32<elf>   \-PE  7e870000-7ea64000   \               user32 ELF 7ea64000-7ea7b000   Deferred        winevdm<elf>   \-PE  7ea70000-7ea7b000   \               winevdm ELF 7eef5000-7efc8000   Deferred        libm.so.6 ELF 7efcb000-7efd5000   Deferred        libuuid.so.1 ELF 7efd5000-7efea000   Deferred        libnss_files.so.2 ELF 7efea000-7f000000   Deferred        wow64cpu<elf>   \-PE  7eff0000-7f000000   \               wow64cpu ELF f7ba0000-f7ba5000   Deferred        libxcomposite.so.1 ELF f7ba7000-f7bad000   Deferred        libdl.so.2 ELF f7bad000-f7d57000   Deferred        libc.so.6 ELF f7d57000-f7d79000   Deferred        libpthread.so.0 ELF f7f53000-f7f5b000   Deferred        libxxf86vm.so.1 ELF f7f5b000-f7f60000   Deferred        libxinerama.so.1 ELF f7f83000-f7f89000   Deferred        libxau.so.6 ELF f7f89000-f7fb4000   Deferred        ld-linux.so.2 Threads: process  tid      prio (all id:s are in hex) 0000000e services.exe     [C:\windows\system32\services.exe]     00000023    0     0000001e    0     0000001a    0     00000015    0     00000012    0     0000000f    0 00000010 explorer.exe     [C:\windows\system32\explorer.exe /desktop]     00000029    0     00000028    0     00000027    0     00000011    0 00000013 winedevice.exe     [C:\windows\system32\winedevice.exe]     0000001b    0     00000019    0     00000018    0     00000014    0 0000001c plugplay.exe     [C:\windows\system32\plugplay.exe]     00000020    0     0000001f    0     0000001d    0 00000021 winedevice.exe     [C:\windows\system32\winedevice.exe]     00000026    0     00000025    0     00000024    0     00000022    0 0000002a (D) C:\windows\system32\winevdm.exe     [C:\windows\system32\winevdm.exe --app-name D:\setup.exe D:\setup.exe]     00000034    0     00000033    0 <==     00000031   15     00000030    0     0000002f    0     0000002b    0 00000037 explorer.exe     [C:\windows\system32\explorer.exe /desktop]     0000003b    0     0000003a    0     00000039    0     00000038    0 System information:     Wine build: wine-4.0-rc2 (Staging)     Platform: i386     Version: Windows 3.1     Host system: Linux     Host version: 4.19.10-300.fc29.x86_64 ``

I’ve also tried running it as Windows 95, but I get the black screen with the same error window which requires using ‘kill’ to get the wine processes to stop.

Any suggestions?