Python Forum
What is the equivalent python code for c program?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the equivalent python code for c program?
#3
Don't understand why you need |. If numbers are not greater then 255.
member = float(sum([i << s for i, s in zip([0,0,64,65], [0, 8, 16, 24])]))
print(member)
Output:
1094713344.0

Quote:float member = *(float *)&d;
Numpy might have a better solution then this.
import numpy as np

array = np.array((0,0,64,65), np.int32) << np.array((0, 8, 16, 24), np.int32)
d = np.sum(array)
member = np.array((d, 0))
member.dtype = np.float32
print(member[0])

Output:
#include <stdio.h> int main() { unsigned long d = (64 << 16) + (65 << 24); float member = *(float *)&d; printf("Float output=%f\n\n", member); // 12.0 printf("%lu", d); // 1094713344.0 return 0; }
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: What is the equivalent python code for c program? - by Windspar - Jan-09-2018, 05:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python equivalent of Matlab code kwokmaster 5 7,242 Apr-03-2020, 12:02 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020