You are the poster boy for why people should hire a professional home inspector before buying any house. The words "2X4" and "floor joist" should never be used together. Of course you do have some options but nothing you have or will do can even come close to being "up to code". This was obviously not intended to be used as a floor and it is patently NOT SAFE to do so. If you have any incidents or legal or insurance claims from this property there is no way your homeowners insurance will cover it. You and the person you bought the home from are in violation of the building code. You should get a building permit and a professional architect or engineer to design an appropriate fix. If there isn't enough head room below, you need to put 2x10 or appropriate sized joists resting on the wall top plate (after removing all of the upstairs subfloor). If you do any work to this without a permit etc. then you will probably still be liable after you sell your home. You are dancing on a ceiling, it is not a floor.