Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.
Zero Tolerance for Disrespect

Experimental Float Reader

Featured Replies

  • Author
  • Localization

El Duderino, posted Sun Aug 24, 2014 7:38 pm (279)


I was bored and looked at the Wikipedia article on floating point numbers.
Actually the math was the only part I could understand and said "To hell with the actual article!" :lol:
Anyway, I've only tested this on FP32 and FP16s because that's all I have.....plus I was feeling fruity and "added a few". :roll:
Also, it only takes 2 lines of code (1 if you disregard the elif line) to add a new format - pretty simple.

EDIT: Needs the bitreader: http://opensourcehacker.com/2010/09/08/bitreader-python-module-for-reading-bits-from-bytes/

Code:
def mb(n):
   l = []
   k = '{:08b}'.format(n)
   for x in k: l.append(int(x))
   return l



def rdf(data,bits,order):
   e,sign,exponent,significand,bias = -1,0,0,0,0
   if bits == 512:     # satire
      sign,exponent,significand,bias = 1,25,487,16777215
   elif bits == 256:   # scientific applications only please
      sign,exponent,significand,bias = 1,20,236,524287
   elif bits == 128:
      sign,exponent,significand,bias = 1,15,112,16383
   elif bits == 80:
      sign,exponent,significand,bias = 1,15,64,16383
   elif bits == 64:
      sign,exponent,significand,bias = 1,11,52,1023
   elif bits == 32:
      sign,exponent,significand,bias = 1,8,23,127
   elif bits == 16:
      sign,exponent,significand,bias = 1,5,10,15
   elif bits == 14:
      exponent,significand,bias = 5,9,15
   elif bits == 11:
      exponent,significand,bias = 5,6,15
   elif bits == 10:
      exponent,significand,bias = 5,5,15
   elif bits == 8:    # more satire
      exponent,significand,bias = 3,5,3
   elif bits == 5:    # a moose once bit my sister
      exponent,significand,bias = 2,3,1
   else:
      print '\n\n\n\n\n\n\n\n\n\n\n\n'
      print 'Congradulations! You\'re an idiot!'
      print '\n\n\n\n'
   if sign != 0:   
      spec = ['sign',sign, 'exponent',exponent, 'significand',significand]
   else:
      spec = ['exponent',exponent, 'significand',significand]
   if order[:3].lower() == 'big':
      reader = BitReader(spec, BitReader.BIG_ENDIAN)
   elif order[:6].lower() == 'little':
      reader = BitReader(spec, BitReader.LITTLE_ENDIAN)
   else:
      print '\n\n'
      print 'No such byte order as:  %s'%order
      print '\n\n'
   vBits = reader.read(data)
   ex = vBits.exponent - bias
   fr = mb(vBits.significand)
   whatsYourSign = vBits.sign
   while len(fr)       fr.insert(0,0)
   temp=[]
   for j in fr:
      if j == 1:
         temp.append(2**e)
      e-=1
   val = (sum(temp) 1) * 2**ex
   if whatsYourSign != 0:
      val *= -1
   return val





#I'm so sick of all that "foo"/"bar"/"baz" garbage!
cougarMom = []

for boyToy in range(100):
   px = struct.unpack("2B", fh.read(2))
   x = rdf(px,16,'bIG')
   py = struct.unpack("2B", fh.read(2))
   y = rdf(py,16,'biG')
   pz = struct.unpack("2B", fh.read(2))
   z = rdf(pz,16,'*SPAM*')
   struct.unpack("26B",fh.read(26))[0]
   cougarMom.append((x,y,z))



fh.close()
  • Author
  • Localization

aluigi, posted Sun Aug 24, 2014 7:45 pm (280)


that cougarMom array made my day :)
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.