<< Chapter < Page Chapter >> Page >

2.- Sử dụng một cấu trúc dữ liệu nào đó để biểu diễn cho một số nguyên, chẳng hạn sử dụng một chuỗi kí tự, trong đó mỗi kí tự lưu trữ môt chữ số. Ưu điểm của phương pháp là tập các giá trị nguyên sẽ rất lớn (số các chữ số trong một nguyên có thể bằng chiều dài của chuỗi kí tự biểu diễn cho nó). Nhược điểm của phương pháp là chúng ta phải xây dựng các chương trình con để thực hiện các phép tính số học và dĩ nhiên tốc độ thực hiện của các chương trình con này sẽ chậm hơn các phép tính được xây dựng trong phần cứng.

Các thuộc tính (chủ yếu là kiểu dữ liệu) của ÐTDL sơ cấp được xử lý bằng 2 cách chính như sau:

1.- Các thuộc tính của ÐTDL có thể được xác định trong khi biên dịch bởi trình biên dịch. Các thuộc tính này sẽ được lưu trữ trong bộ dịch của ngôn ngữ (chẳng hạn bảng danh biểu) và khi cần sẽ tìm lại các thuộc tính này để sử dụng. Ðó là phương pháp thông dụng trong các ngôn ngữ biên dịch như FORTRAN, C và Pascal, nơi mà tính hiệu quả của việc sử dụng bộ nhớ và tốc độ thực hiện chương trình là những mục tiêu trên hết.

2.- Các thuộc tính có thể được lưu trữ trong bộ mô tả như là một phần của ÐTDL tại thời gian thực hiện. Ðây là phương pháp thông dụng trong các ngôn ngữ thông dịch như LISP và SNOBOL4, nơi mà tính linh hoạt mềm dẻo là mục tiêu trước hết chứ không phải là tính hiệu quả.

Cài đặt phép toán

Mỗi một phép toán thao tác trên các ÐTDL của một kiểu dữ liệu sơ cấp đã cho có thể được cài đặt bằng một trong 3 cách như sau:

1.- Như là một phép toán phần cứng trực tiếp, nếu sự biểu diễn bộ nhớ của ÐTDL là sự biểu diễn của phần cứng. Ví dụ nếu các số nguyên được lưu trữ bằng cách dùng biểu diễn phần cứng cho số nguyên thì các phép toán như phép cộng, trừ và các phép toán số học khác của số nguyên có thể được thực hiện bằng cách dùng các phép toán số học cho số nguyên đã được xây dựng trong phần cứng.

2.- Như là một thủ tục hoặc hàm thực hiện các phép toán. Ví dụ phép toán lấy căn bậc hai thông thường không được cung cấp một cách trực tiếp như là một phép toán trong phần cứng ngay cả khi các số được biểu diễn bằng sự biểu diễn của phần cứng và vì vậy nó được cài đặt như là một chương trình con tính căn bậc hai. Nếu các ÐTDL không được biểu diễn bằng sự biểu diễn xác định bởi phần cứng thì tất cả các phép toán phải được mô phỏng bởi phần mềm.

3.- Như là một chuỗi các dòng mã lệnh dùng để thực hiện phép toán như là một dãy các phép toán phần cứng. Ví dụ hàm lấy trị tuyệt đối của một số được định nghĩa là:

ABS(x) = { x nêu x 0 - x nêu x < 0 size 12{ left lbrace matrix { "x nêu x ">= " 0" {} ## "- x nêu x "<" 0 " } right none } {} thường được cài đặt như là một chuỗi các mã lệnh:

1.- Nhận giá trị x từ bộ nhớ

2.- Nếu x>=0 thì bỏ qua chỉ thị kế tiếp

3.- Ðặt x = -x

4.- Lưu x vào bộ nhớ

Trong đó mỗi một dòng mã lệnh được thực hiện bởi một phép toán trong phần cứng.

Kiểu dữ liệu số

Hầu hết các ngôn ngữ lập trình đều có các kiểu dữ liệu số, nhưng các chi tiết của sự đặc tả và phép cài đặt các kiểu này có nhiều điểm khác nhau. Kiểu số nguyên và kiểu số thực là phổ biến nhất bởi vì chúng dựa một cách trực tiếp vào phần cứng của máy tính.

Số nguyên

Sự đặc tả

Đặc tả các thuộc tính: Một ÐTDL của kiểu số nguyên không có thuộc tính nào khác ngoài kiểu của nó.

Questions & Answers

what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
What are the treatment for autism?
Magret Reply
hello. autism is a umbrella term. autistic kids have different disorder overlapping. for example. a kid may show symptoms of ADHD and also learning disabilities. before treatment please make sure the kid doesn't have physical disabilities like hearing..vision..speech problem. sometimes these
Jharna
continue.. sometimes due to these physical problems..the diagnosis may be misdiagnosed. treatment for autism. well it depends on the severity. since autistic kids have problems in communicating and adopting to the environment.. it's best to expose the child in situations where the child
Jharna
child interact with other kids under doc supervision. play therapy. speech therapy. Engaging in different activities that activate most parts of the brain.. like drawing..painting. matching color board game. string and beads game. the more you interact with the child the more effective
Jharna
results you'll get.. please consult a therapist to know what suits best on your child. and last as a parent. I know sometimes it's overwhelming to guide a special kid. but trust the process and be strong and patient as a parent.
Jharna
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ngôn ngữ lập trình. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10783/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ngôn ngữ lập trình' conversation and receive update notifications?

Ask