Suneido

Integrated Application Platform

  • Home
  • Learning
    • Suneido Manual
    • Beginners
      • Inside Suneido
      • The Suneido Programming Language
      • The Suneido Database
      • Installing Suneido
      • Building Suneido
      • IDE Go To Tour
      • Upgrading To A New Release
    • Advanced
      • Canvas Control
      • DrawControl Part 1
      • DrawControl Part 2
      • DrawControl Part 3
      • SAX Like XML Processing
      • A Plug-In Architecture
      • A Simple Wizard Framework
      • An HTML Include Facility
      • An RSS 2 Feed Creator
      • MIME Generation
      • A New Add-on Facility
      • Workspace Improvement Hack
    • Mockito for Suneido
    • The Suneido Task Scheduler
    • Contributing To Suneido
    • Contributor Assignment of Copyright
    • Language Translation
    • Future Directions
    • Interview With Andrew Mckinlay
  • Forum
    • Announcements
    • Internals & Enhancements
    • Cookbook
    • General
  • FAQ
  • Screenshots
  • Downloads
  • Links

Writing a file with hex values

Integrated Application Platform › Forums › General › Writing a file with hex values

  • This topic has 3 replies, 3 voices, and was last updated 5 years, 5 months ago by ajith.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • August 5, 2017 at 11:31 pm #1314
    ajith
    Participant

    Hi,

    I was trying to write unicode hex values directly into a file using Suneido.
    When I try

    File("test.txt", mode = "ab")
    		{ |f|
    		f.Write(0x0D06)}

    the number 3334 gets written. If I use

    
    f.Write(Pack(0x0D06))
    

    then the 0D06 is written but preceeded by 0381

    How can I get just the hexvalue written in the file?
    Thanks,
    ajith

    August 6, 2017 at 11:59 am #1317
    liqian
    Participant

    I don’t think there is an existing function to display hex value string

    so we need something like the following code

    n = 0x0D06
    map = ‘0123456789ABCD’
    s = ”
    while (n >= 1)
    {
    c = n % 16
    s = map[c] $ s
    n = (n – c) / 16
    }
    s.LeftFill(4, ‘0’)

    we probably could add to Numbers as well

    f.Write(0x0D06) converts the hex number to decimal number automatically, the future version of cSuneido will not convert automatically anymore, and will throw error instead.

    August 6, 2017 at 1:13 pm #1319
    amckinlay
    Keymaster

    The trick is to write a string containing the bytes you want to output.

    e.g. f.Write('\x0d\x06')

    Note: You need to get the byte order correct i.e. it might need to be \x06\x0d

    The upcoming change in Suneido is that it will not automatically convert strings to number e.g. for arithmetic. However, literal numbers like 0x0D06 will still be handled. 0x0d06 and 3334 are just different representations for the same underlying number.

    August 9, 2017 at 5:00 am #1321
    ajith
    Participant

    Thanks both of you for your replies. I tried what Andrew suggested and it is working well.

    Thanks
    ajith

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Log In

Search Forums

Log In
Welcome to the new Suneido Web Site and Forum.
Register
Lost Password
users of the previous PHPBB Forum should be able to log in with their previous username and password.

Recent Topics

  • Alpha copy of gSuneido to play with
  • how to start jsuneido ?
  • Problem Starting Suneido…
  • Dialog not showing buttons
  • New link for Suneidojo

Contact Us | Legal Statement | Privacy Statement | SiteMap

Copyright © 2023 Axon® Development Corporation. All Rights Reserved. - Open Source Integrated Database and Programming Language